richtextbuffer.h 209 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/richtext/richtextbuffer.h
  3. // Purpose: Buffer for wxRichTextCtrl
  4. // Author: Julian Smart
  5. // Modified by:
  6. // Created: 2005-09-30
  7. // Copyright: (c) Julian Smart
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_RICHTEXTBUFFER_H_
  11. #define _WX_RICHTEXTBUFFER_H_
  12. /*
  13. Data structures
  14. ===============
  15. Data is represented by a hierarchy of objects, all derived from
  16. wxRichTextObject.
  17. The top of the hierarchy is the buffer, a kind of wxRichTextParagraphLayoutBox.
  18. These boxes will allow flexible placement of text boxes on a page, but
  19. for now there is a single box representing the document, and this box is
  20. a wxRichTextParagraphLayoutBox which contains further wxRichTextParagraph
  21. objects, each of which can include text and images.
  22. Each object maintains a range (start and end position) measured
  23. from the start of the main parent box.
  24. A paragraph object knows its range, and a text fragment knows its range
  25. too. So, a character or image in a page has a position relative to the
  26. start of the document, and a character in an embedded text box has
  27. a position relative to that text box. For now, we will not be dealing with
  28. embedded objects but it's something to bear in mind for later.
  29. Note that internally, a range (5,5) represents a range of one character.
  30. In the public wx[Rich]TextCtrl API, this would be passed to e.g. SetSelection
  31. as (5,6). A paragraph with one character might have an internal range of (0, 1)
  32. since the end of the paragraph takes up one position.
  33. Layout
  34. ======
  35. When Layout is called on an object, it is given a size which the object
  36. must limit itself to, or one or more flexible directions (vertical
  37. or horizontal). So for example a centered paragraph is given the page
  38. width to play with (minus any margins), but can extend indefinitely
  39. in the vertical direction. The implementation of Layout can then
  40. cache the calculated size and position within the parent.
  41. */
  42. /*!
  43. * Includes
  44. */
  45. #include "wx/defs.h"
  46. #if wxUSE_RICHTEXT
  47. #include "wx/list.h"
  48. #include "wx/textctrl.h"
  49. #include "wx/bitmap.h"
  50. #include "wx/image.h"
  51. #include "wx/cmdproc.h"
  52. #include "wx/txtstrm.h"
  53. #include "wx/variant.h"
  54. #include "wx/position.h"
  55. #if wxUSE_DATAOBJ
  56. #include "wx/dataobj.h"
  57. #endif
  58. // Compatibility
  59. //#define wxRichTextAttr wxTextAttr
  60. #define wxTextAttrEx wxTextAttr
  61. // Setting wxRICHTEXT_USE_OWN_CARET to 1 implements a
  62. // caret reliably without using wxClientDC in case there
  63. // are platform-specific problems with the generic caret.
  64. #if defined(__WXGTK__) || defined(__WXMAC__)
  65. #define wxRICHTEXT_USE_OWN_CARET 1
  66. #else
  67. #define wxRICHTEXT_USE_OWN_CARET 0
  68. #endif
  69. // Switch off for binary compatibility, on for faster drawing
  70. // Note: this seems to be buggy (overzealous use of extents) so
  71. // don't use for now
  72. #define wxRICHTEXT_USE_OPTIMIZED_LINE_DRAWING 0
  73. // The following two symbols determine whether an output implementation
  74. // is present. To switch the relevant one on, set wxRICHTEXT_USE_XMLDOCUMENT_OUTPUT in
  75. // richtextxml.cpp. By default, the faster direct output implementation is used.
  76. // Include the wxXmlDocument implementation for output
  77. #define wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT 1
  78. // Include the faster, direct implementation for output
  79. #define wxRICHTEXT_HAVE_DIRECT_OUTPUT 1
  80. /**
  81. The line break character that can be embedded in content.
  82. */
  83. extern WXDLLIMPEXP_RICHTEXT const wxChar wxRichTextLineBreakChar;
  84. /**
  85. File types in wxRichText context.
  86. */
  87. enum wxRichTextFileType
  88. {
  89. wxRICHTEXT_TYPE_ANY = 0,
  90. wxRICHTEXT_TYPE_TEXT,
  91. wxRICHTEXT_TYPE_XML,
  92. wxRICHTEXT_TYPE_HTML,
  93. wxRICHTEXT_TYPE_RTF,
  94. wxRICHTEXT_TYPE_PDF
  95. };
  96. /*
  97. * Forward declarations
  98. */
  99. class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextCtrl;
  100. class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextObject;
  101. class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextImage;
  102. class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextPlainText;
  103. class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextCacheObject;
  104. class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextObjectList;
  105. class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextLine;
  106. class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextParagraph;
  107. class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextFileHandler;
  108. class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextDrawingHandler;
  109. class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextField;
  110. class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextFieldType;
  111. class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextStyleSheet;
  112. class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextListStyleDefinition;
  113. class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextEvent;
  114. class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextRenderer;
  115. class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextBuffer;
  116. class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextXMLHandler;
  117. class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextParagraphLayoutBox;
  118. class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextImageBlock;
  119. class WXDLLIMPEXP_FWD_XML wxXmlNode;
  120. class wxRichTextFloatCollector;
  121. class WXDLLIMPEXP_FWD_BASE wxDataInputStream;
  122. class WXDLLIMPEXP_FWD_BASE wxDataOutputStream;
  123. /**
  124. Flags determining the available space, passed to Layout.
  125. */
  126. #define wxRICHTEXT_FIXED_WIDTH 0x01
  127. #define wxRICHTEXT_FIXED_HEIGHT 0x02
  128. #define wxRICHTEXT_VARIABLE_WIDTH 0x04
  129. #define wxRICHTEXT_VARIABLE_HEIGHT 0x08
  130. // Only lay out the part of the buffer that lies within
  131. // the rect passed to Layout.
  132. #define wxRICHTEXT_LAYOUT_SPECIFIED_RECT 0x10
  133. /**
  134. Flags to pass to Draw
  135. */
  136. // Ignore paragraph cache optimization, e.g. for printing purposes
  137. // where one line may be drawn higher (on the next page) compared
  138. // with the previous line
  139. #define wxRICHTEXT_DRAW_IGNORE_CACHE 0x01
  140. #define wxRICHTEXT_DRAW_SELECTED 0x02
  141. #define wxRICHTEXT_DRAW_PRINT 0x04
  142. #define wxRICHTEXT_DRAW_GUIDELINES 0x08
  143. /**
  144. Flags returned from hit-testing, or passed to hit-test function.
  145. */
  146. enum wxRichTextHitTestFlags
  147. {
  148. // The point was not on this object
  149. wxRICHTEXT_HITTEST_NONE = 0x01,
  150. // The point was before the position returned from HitTest
  151. wxRICHTEXT_HITTEST_BEFORE = 0x02,
  152. // The point was after the position returned from HitTest
  153. wxRICHTEXT_HITTEST_AFTER = 0x04,
  154. // The point was on the position returned from HitTest
  155. wxRICHTEXT_HITTEST_ON = 0x08,
  156. // The point was on space outside content
  157. wxRICHTEXT_HITTEST_OUTSIDE = 0x10,
  158. // Only do hit-testing at the current level (don't traverse into top-level objects)
  159. wxRICHTEXT_HITTEST_NO_NESTED_OBJECTS = 0x20,
  160. // Ignore floating objects
  161. wxRICHTEXT_HITTEST_NO_FLOATING_OBJECTS = 0x40,
  162. // Don't recurse into objects marked as atomic
  163. wxRICHTEXT_HITTEST_HONOUR_ATOMIC = 0x80
  164. };
  165. /**
  166. Flags for GetRangeSize.
  167. */
  168. #define wxRICHTEXT_FORMATTED 0x01
  169. #define wxRICHTEXT_UNFORMATTED 0x02
  170. #define wxRICHTEXT_CACHE_SIZE 0x04
  171. #define wxRICHTEXT_HEIGHT_ONLY 0x08
  172. /**
  173. Flags for SetStyle/SetListStyle.
  174. */
  175. #define wxRICHTEXT_SETSTYLE_NONE 0x00
  176. // Specifies that this operation should be undoable
  177. #define wxRICHTEXT_SETSTYLE_WITH_UNDO 0x01
  178. // Specifies that the style should not be applied if the
  179. // combined style at this point is already the style in question.
  180. #define wxRICHTEXT_SETSTYLE_OPTIMIZE 0x02
  181. // Specifies that the style should only be applied to paragraphs,
  182. // and not the content. This allows content styling to be
  183. // preserved independently from that of e.g. a named paragraph style.
  184. #define wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY 0x04
  185. // Specifies that the style should only be applied to characters,
  186. // and not the paragraph. This allows content styling to be
  187. // preserved independently from that of e.g. a named paragraph style.
  188. #define wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY 0x08
  189. // For SetListStyle only: specifies starting from the given number, otherwise
  190. // deduces number from existing attributes
  191. #define wxRICHTEXT_SETSTYLE_RENUMBER 0x10
  192. // For SetListStyle only: specifies the list level for all paragraphs, otherwise
  193. // the current indentation will be used
  194. #define wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL 0x20
  195. // Resets the existing style before applying the new style
  196. #define wxRICHTEXT_SETSTYLE_RESET 0x40
  197. // Removes the given style instead of applying it
  198. #define wxRICHTEXT_SETSTYLE_REMOVE 0x80
  199. /**
  200. Flags for SetProperties.
  201. */
  202. #define wxRICHTEXT_SETPROPERTIES_NONE 0x00
  203. // Specifies that this operation should be undoable
  204. #define wxRICHTEXT_SETPROPERTIES_WITH_UNDO 0x01
  205. // Specifies that the properties should only be applied to paragraphs,
  206. // and not the content.
  207. #define wxRICHTEXT_SETPROPERTIES_PARAGRAPHS_ONLY 0x02
  208. // Specifies that the properties should only be applied to characters,
  209. // and not the paragraph.
  210. #define wxRICHTEXT_SETPROPERTIES_CHARACTERS_ONLY 0x04
  211. // Resets the existing properties before applying the new properties.
  212. #define wxRICHTEXT_SETPROPERTIES_RESET 0x08
  213. // Removes the given properties instead of applying them.
  214. #define wxRICHTEXT_SETPROPERTIES_REMOVE 0x10
  215. /**
  216. Flags for object insertion.
  217. */
  218. #define wxRICHTEXT_INSERT_NONE 0x00
  219. #define wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE 0x01
  220. #define wxRICHTEXT_INSERT_INTERACTIVE 0x02
  221. // A special flag telling the buffer to keep the first paragraph style
  222. // as-is, when deleting a paragraph marker. In future we might pass a
  223. // flag to InsertFragment and DeleteRange to indicate the appropriate mode.
  224. #define wxTEXT_ATTR_KEEP_FIRST_PARA_STYLE 0x20000000
  225. /**
  226. Default superscript/subscript font multiplication factor.
  227. */
  228. #define wxSCRIPT_MUL_FACTOR 1.5
  229. /**
  230. The type for wxTextAttrDimension flags.
  231. */
  232. typedef unsigned short wxTextAttrDimensionFlags;
  233. /**
  234. Miscellaneous text box flags
  235. */
  236. enum wxTextBoxAttrFlags
  237. {
  238. wxTEXT_BOX_ATTR_FLOAT = 0x00000001,
  239. wxTEXT_BOX_ATTR_CLEAR = 0x00000002,
  240. wxTEXT_BOX_ATTR_COLLAPSE_BORDERS = 0x00000004,
  241. wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT = 0x00000008,
  242. wxTEXT_BOX_ATTR_BOX_STYLE_NAME = 0x00000010
  243. };
  244. /**
  245. Whether a value is present, used in dimension flags.
  246. */
  247. enum wxTextAttrValueFlags
  248. {
  249. wxTEXT_ATTR_VALUE_VALID = 0x1000,
  250. wxTEXT_ATTR_VALUE_VALID_MASK = 0x1000
  251. };
  252. /**
  253. Units, included in the dimension value.
  254. */
  255. enum wxTextAttrUnits
  256. {
  257. wxTEXT_ATTR_UNITS_TENTHS_MM = 0x0001,
  258. wxTEXT_ATTR_UNITS_PIXELS = 0x0002,
  259. wxTEXT_ATTR_UNITS_PERCENTAGE = 0x0004,
  260. wxTEXT_ATTR_UNITS_POINTS = 0x0008,
  261. wxTEXT_ATTR_UNITS_HUNDREDTHS_POINT = 0x0100,
  262. wxTEXT_ATTR_UNITS_MASK = 0x010F
  263. };
  264. /**
  265. Position alternatives, included in the dimension flags.
  266. */
  267. enum wxTextBoxAttrPosition
  268. {
  269. wxTEXT_BOX_ATTR_POSITION_STATIC = 0x0000, // Default is static, i.e. as per normal layout
  270. wxTEXT_BOX_ATTR_POSITION_RELATIVE = 0x0010, // Relative to the relevant edge
  271. wxTEXT_BOX_ATTR_POSITION_ABSOLUTE = 0x0020, // Relative to the parent
  272. wxTEXT_BOX_ATTR_POSITION_FIXED = 0x0040, // Relative to the top-level window
  273. wxTEXT_BOX_ATTR_POSITION_MASK = 0x00F0
  274. };
  275. /**
  276. @class wxTextAttrDimension
  277. A class representing a rich text dimension, including units and position.
  278. @library{wxrichtext}
  279. @category{richtext}
  280. @see wxRichTextAttr, wxRichTextCtrl, wxTextAttrDimensions
  281. */
  282. class WXDLLIMPEXP_RICHTEXT wxTextAttrDimension
  283. {
  284. public:
  285. /**
  286. Default constructor.
  287. */
  288. wxTextAttrDimension() { Reset(); }
  289. /**
  290. Constructor taking value and units flag.
  291. */
  292. wxTextAttrDimension(int value, wxTextAttrUnits units = wxTEXT_ATTR_UNITS_TENTHS_MM) { m_value = value; m_flags = units|wxTEXT_ATTR_VALUE_VALID; }
  293. /**
  294. Resets the dimension value and flags.
  295. */
  296. void Reset() { m_value = 0; m_flags = 0; }
  297. /**
  298. Partial equality test. If @a weakTest is @true, attributes of this object do not
  299. have to be present if those attributes of @a dim are present. If @a weakTest is
  300. @false, the function will fail if an attribute is present in @a dim but not
  301. in this object.
  302. */
  303. bool EqPartial(const wxTextAttrDimension& dim, bool weakTest = true) const;
  304. /** Apply the dimension, but not those identical to @a compareWith if present.
  305. */
  306. bool Apply(const wxTextAttrDimension& dim, const wxTextAttrDimension* compareWith = NULL);
  307. /** Collects the attributes that are common to a range of content, building up a note of
  308. which attributes are absent in some objects and which clash in some objects.
  309. */
  310. void CollectCommonAttributes(const wxTextAttrDimension& attr, wxTextAttrDimension& clashingAttr, wxTextAttrDimension& absentAttr);
  311. /**
  312. Equality operator.
  313. */
  314. bool operator==(const wxTextAttrDimension& dim) const { return m_value == dim.m_value && m_flags == dim.m_flags; }
  315. /**
  316. Returns the integer value of the dimension.
  317. */
  318. int GetValue() const { return m_value; }
  319. /**
  320. Returns the floating-pointing value of the dimension in mm.
  321. */
  322. float GetValueMM() const { return m_value / 10.0f; }
  323. /**
  324. Sets the value of the dimension in mm.
  325. */
  326. void SetValueMM(float value) { m_value = (int) ((value * 10.0f) + 0.5f); m_flags |= wxTEXT_ATTR_VALUE_VALID; }
  327. /**
  328. Sets the integer value of the dimension.
  329. */
  330. void SetValue(int value) { m_value = value; m_flags |= wxTEXT_ATTR_VALUE_VALID; }
  331. /**
  332. Sets the integer value of the dimension, passing dimension flags.
  333. */
  334. void SetValue(int value, wxTextAttrDimensionFlags flags) { SetValue(value); m_flags = flags; }
  335. /**
  336. Sets the integer value and units.
  337. */
  338. void SetValue(int value, wxTextAttrUnits units) { m_value = value; m_flags = units | wxTEXT_ATTR_VALUE_VALID; }
  339. /**
  340. Sets the dimension.
  341. */
  342. void SetValue(const wxTextAttrDimension& dim) { (*this) = dim; }
  343. /**
  344. Gets the units of the dimension.
  345. */
  346. wxTextAttrUnits GetUnits() const { return (wxTextAttrUnits) (m_flags & wxTEXT_ATTR_UNITS_MASK); }
  347. /**
  348. Sets the units of the dimension.
  349. */
  350. void SetUnits(wxTextAttrUnits units) { m_flags &= ~wxTEXT_ATTR_UNITS_MASK; m_flags |= units; }
  351. /**
  352. Gets the position flags.
  353. */
  354. wxTextBoxAttrPosition GetPosition() const { return (wxTextBoxAttrPosition) (m_flags & wxTEXT_BOX_ATTR_POSITION_MASK); }
  355. /**
  356. Sets the position flags.
  357. */
  358. void SetPosition(wxTextBoxAttrPosition pos) { m_flags &= ~wxTEXT_BOX_ATTR_POSITION_MASK; m_flags |= pos; }
  359. /**
  360. Returns @true if the dimension is valid.
  361. */
  362. bool IsValid() const { return (m_flags & wxTEXT_ATTR_VALUE_VALID) != 0; }
  363. /**
  364. Sets the valid flag.
  365. */
  366. void SetValid(bool b) { m_flags &= ~wxTEXT_ATTR_VALUE_VALID_MASK; m_flags |= (b ? wxTEXT_ATTR_VALUE_VALID : 0); }
  367. /**
  368. Gets the dimension flags.
  369. */
  370. wxTextAttrDimensionFlags GetFlags() const { return m_flags; }
  371. /**
  372. Sets the dimension flags.
  373. */
  374. void SetFlags(wxTextAttrDimensionFlags flags) { m_flags = flags; }
  375. int m_value;
  376. wxTextAttrDimensionFlags m_flags;
  377. };
  378. /**
  379. @class wxTextAttrDimensions
  380. A class for left, right, top and bottom dimensions.
  381. @library{wxrichtext}
  382. @category{richtext}
  383. @see wxRichTextAttr, wxRichTextCtrl, wxTextAttrDimension
  384. */
  385. class WXDLLIMPEXP_RICHTEXT wxTextAttrDimensions
  386. {
  387. public:
  388. /**
  389. Default constructor.
  390. */
  391. wxTextAttrDimensions() {}
  392. /**
  393. Resets the value and flags for all dimensions.
  394. */
  395. void Reset() { m_left.Reset(); m_top.Reset(); m_right.Reset(); m_bottom.Reset(); }
  396. /**
  397. Equality operator.
  398. */
  399. bool operator==(const wxTextAttrDimensions& dims) const { return m_left == dims.m_left && m_top == dims.m_top && m_right == dims.m_right && m_bottom == dims.m_bottom; }
  400. /**
  401. Partial equality test. If @a weakTest is @true, attributes of this object do not
  402. have to be present if those attributes of @a dim sare present. If @a weakTest is
  403. @false, the function will fail if an attribute is present in @a dims but not
  404. in this object.
  405. */
  406. bool EqPartial(const wxTextAttrDimensions& dims, bool weakTest = true) const;
  407. /**
  408. Apply to 'this', but not if the same as @a compareWith.
  409. */
  410. bool Apply(const wxTextAttrDimensions& dims, const wxTextAttrDimensions* compareWith = NULL);
  411. /**
  412. Collects the attributes that are common to a range of content, building up a note of
  413. which attributes are absent in some objects and which clash in some objects.
  414. */
  415. void CollectCommonAttributes(const wxTextAttrDimensions& attr, wxTextAttrDimensions& clashingAttr, wxTextAttrDimensions& absentAttr);
  416. /**
  417. Remove specified attributes from this object.
  418. */
  419. bool RemoveStyle(const wxTextAttrDimensions& attr);
  420. /**
  421. Gets the left dimension.
  422. */
  423. const wxTextAttrDimension& GetLeft() const { return m_left; }
  424. wxTextAttrDimension& GetLeft() { return m_left; }
  425. /**
  426. Gets the right dimension.
  427. */
  428. const wxTextAttrDimension& GetRight() const { return m_right; }
  429. wxTextAttrDimension& GetRight() { return m_right; }
  430. /**
  431. Gets the top dimension.
  432. */
  433. const wxTextAttrDimension& GetTop() const { return m_top; }
  434. wxTextAttrDimension& GetTop() { return m_top; }
  435. /**
  436. Gets the bottom dimension.
  437. */
  438. const wxTextAttrDimension& GetBottom() const { return m_bottom; }
  439. wxTextAttrDimension& GetBottom() { return m_bottom; }
  440. /**
  441. Are all dimensions valid?
  442. */
  443. bool IsValid() const { return m_left.IsValid() && m_top.IsValid() && m_right.IsValid() && m_bottom.IsValid(); }
  444. wxTextAttrDimension m_left;
  445. wxTextAttrDimension m_top;
  446. wxTextAttrDimension m_right;
  447. wxTextAttrDimension m_bottom;
  448. };
  449. /**
  450. @class wxTextAttrSize
  451. A class for representing width and height.
  452. @library{wxrichtext}
  453. @category{richtext}
  454. @see wxRichTextAttr, wxRichTextCtrl, wxTextAttrDimension
  455. */
  456. class WXDLLIMPEXP_RICHTEXT wxTextAttrSize
  457. {
  458. public:
  459. /**
  460. Default constructor.
  461. */
  462. wxTextAttrSize() {}
  463. /**
  464. Resets the width and height dimensions.
  465. */
  466. void Reset() { m_width.Reset(); m_height.Reset(); }
  467. /**
  468. Equality operator.
  469. */
  470. bool operator==(const wxTextAttrSize& size) const { return m_width == size.m_width && m_height == size.m_height ; }
  471. /**
  472. Partial equality test. If @a weakTest is @true, attributes of this object do not
  473. have to be present if those attributes of @a size are present. If @a weakTest is
  474. @false, the function will fail if an attribute is present in @a size but not
  475. in this object.
  476. */
  477. bool EqPartial(const wxTextAttrSize& size, bool weakTest = true) const;
  478. /**
  479. Apply to this object, but not if the same as @a compareWith.
  480. */
  481. bool Apply(const wxTextAttrSize& dims, const wxTextAttrSize* compareWith = NULL);
  482. /**
  483. Collects the attributes that are common to a range of content, building up a note of
  484. which attributes are absent in some objects and which clash in some objects.
  485. */
  486. void CollectCommonAttributes(const wxTextAttrSize& attr, wxTextAttrSize& clashingAttr, wxTextAttrSize& absentAttr);
  487. /**
  488. Removes the specified attributes from this object.
  489. */
  490. bool RemoveStyle(const wxTextAttrSize& attr);
  491. /**
  492. Returns the width.
  493. */
  494. wxTextAttrDimension& GetWidth() { return m_width; }
  495. const wxTextAttrDimension& GetWidth() const { return m_width; }
  496. /**
  497. Sets the width.
  498. */
  499. void SetWidth(int value, wxTextAttrDimensionFlags flags) { m_width.SetValue(value, flags); }
  500. /**
  501. Sets the width.
  502. */
  503. void SetWidth(int value, wxTextAttrUnits units) { m_width.SetValue(value, units); }
  504. /**
  505. Sets the width.
  506. */
  507. void SetWidth(const wxTextAttrDimension& dim) { m_width.SetValue(dim); }
  508. /**
  509. Gets the height.
  510. */
  511. wxTextAttrDimension& GetHeight() { return m_height; }
  512. const wxTextAttrDimension& GetHeight() const { return m_height; }
  513. /**
  514. Sets the height.
  515. */
  516. void SetHeight(int value, wxTextAttrDimensionFlags flags) { m_height.SetValue(value, flags); }
  517. /**
  518. Sets the height.
  519. */
  520. void SetHeight(int value, wxTextAttrUnits units) { m_height.SetValue(value, units); }
  521. /**
  522. Sets the height.
  523. */
  524. void SetHeight(const wxTextAttrDimension& dim) { m_height.SetValue(dim); }
  525. /**
  526. Is the size valid?
  527. */
  528. bool IsValid() const { return m_width.IsValid() && m_height.IsValid(); }
  529. wxTextAttrDimension m_width;
  530. wxTextAttrDimension m_height;
  531. };
  532. /**
  533. @class wxTextAttrDimensionConverter
  534. A class to make it easier to convert dimensions.
  535. @library{wxrichtext}
  536. @category{richtext}
  537. @see wxRichTextAttr, wxRichTextCtrl, wxTextAttrDimension
  538. */
  539. class WXDLLIMPEXP_RICHTEXT wxTextAttrDimensionConverter
  540. {
  541. public:
  542. /**
  543. Constructor.
  544. */
  545. wxTextAttrDimensionConverter(wxDC& dc, double scale = 1.0, const wxSize& parentSize = wxDefaultSize);
  546. /**
  547. Constructor.
  548. */
  549. wxTextAttrDimensionConverter(int ppi, double scale = 1.0, const wxSize& parentSize = wxDefaultSize);
  550. /**
  551. Gets the pixel size for the given dimension.
  552. */
  553. int GetPixels(const wxTextAttrDimension& dim, int direction = wxHORIZONTAL) const;
  554. /**
  555. Gets the mm size for the given dimension.
  556. */
  557. int GetTenthsMM(const wxTextAttrDimension& dim) const;
  558. /**
  559. Converts tenths of a mm to pixels.
  560. */
  561. int ConvertTenthsMMToPixels(int units) const;
  562. /**
  563. Converts pixels to tenths of a mm.
  564. */
  565. int ConvertPixelsToTenthsMM(int pixels) const;
  566. /**
  567. Sets the scale factor.
  568. */
  569. void SetScale(double scale) { m_scale = scale; }
  570. /**
  571. Returns the scale factor.
  572. */
  573. double GetScale() const { return m_scale; }
  574. /**
  575. Sets the ppi.
  576. */
  577. void SetPPI(int ppi) { m_ppi = ppi; }
  578. /**
  579. Returns the ppi.
  580. */
  581. int GetPPI() const { return m_ppi; }
  582. /**
  583. Sets the parent size.
  584. */
  585. void SetParentSize(const wxSize& parentSize) { m_parentSize = parentSize; }
  586. /**
  587. Returns the parent size.
  588. */
  589. const wxSize& GetParentSize() const { return m_parentSize; }
  590. int m_ppi;
  591. double m_scale;
  592. wxSize m_parentSize;
  593. };
  594. /**
  595. Border styles, used with wxTextAttrBorder.
  596. */
  597. enum wxTextAttrBorderStyle
  598. {
  599. wxTEXT_BOX_ATTR_BORDER_NONE = 0,
  600. wxTEXT_BOX_ATTR_BORDER_SOLID = 1,
  601. wxTEXT_BOX_ATTR_BORDER_DOTTED = 2,
  602. wxTEXT_BOX_ATTR_BORDER_DASHED = 3,
  603. wxTEXT_BOX_ATTR_BORDER_DOUBLE = 4,
  604. wxTEXT_BOX_ATTR_BORDER_GROOVE = 5,
  605. wxTEXT_BOX_ATTR_BORDER_RIDGE = 6,
  606. wxTEXT_BOX_ATTR_BORDER_INSET = 7,
  607. wxTEXT_BOX_ATTR_BORDER_OUTSET = 8
  608. };
  609. /**
  610. Border style presence flags, used with wxTextAttrBorder.
  611. */
  612. enum wxTextAttrBorderFlags
  613. {
  614. wxTEXT_BOX_ATTR_BORDER_STYLE = 0x0001,
  615. wxTEXT_BOX_ATTR_BORDER_COLOUR = 0x0002
  616. };
  617. /**
  618. Border width symbols for qualitative widths, used with wxTextAttrBorder.
  619. */
  620. enum wxTextAttrBorderWidth
  621. {
  622. wxTEXT_BOX_ATTR_BORDER_THIN = -1,
  623. wxTEXT_BOX_ATTR_BORDER_MEDIUM = -2,
  624. wxTEXT_BOX_ATTR_BORDER_THICK = -3
  625. };
  626. /**
  627. Float styles.
  628. */
  629. enum wxTextBoxAttrFloatStyle
  630. {
  631. wxTEXT_BOX_ATTR_FLOAT_NONE = 0,
  632. wxTEXT_BOX_ATTR_FLOAT_LEFT = 1,
  633. wxTEXT_BOX_ATTR_FLOAT_RIGHT = 2
  634. };
  635. /**
  636. Clear styles.
  637. */
  638. enum wxTextBoxAttrClearStyle
  639. {
  640. wxTEXT_BOX_ATTR_CLEAR_NONE = 0,
  641. wxTEXT_BOX_ATTR_CLEAR_LEFT = 1,
  642. wxTEXT_BOX_ATTR_CLEAR_RIGHT = 2,
  643. wxTEXT_BOX_ATTR_CLEAR_BOTH = 3
  644. };
  645. /**
  646. Collapse mode styles. TODO: can they be switched on per side?
  647. */
  648. enum wxTextBoxAttrCollapseMode
  649. {
  650. wxTEXT_BOX_ATTR_COLLAPSE_NONE = 0,
  651. wxTEXT_BOX_ATTR_COLLAPSE_FULL = 1
  652. };
  653. /**
  654. Vertical alignment values.
  655. */
  656. enum wxTextBoxAttrVerticalAlignment
  657. {
  658. wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_NONE = 0,
  659. wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_TOP = 1,
  660. wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_CENTRE = 2,
  661. wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_BOTTOM = 3
  662. };
  663. /**
  664. @class wxTextAttrBorder
  665. A class representing a rich text object border.
  666. @library{wxrichtext}
  667. @category{richtext}
  668. @see wxRichTextAttr, wxRichTextCtrl, wxRichTextAttrBorders
  669. */
  670. class WXDLLIMPEXP_RICHTEXT wxTextAttrBorder
  671. {
  672. public:
  673. /**
  674. Default constructor.
  675. */
  676. wxTextAttrBorder() { Reset(); }
  677. /**
  678. Equality operator.
  679. */
  680. bool operator==(const wxTextAttrBorder& border) const
  681. {
  682. return m_flags == border.m_flags && m_borderStyle == border.m_borderStyle &&
  683. m_borderColour == border.m_borderColour && m_borderWidth == border.m_borderWidth;
  684. }
  685. /**
  686. Resets the border style, colour, width and flags.
  687. */
  688. void Reset() { m_borderStyle = 0; m_borderColour = 0; m_flags = 0; m_borderWidth.Reset(); }
  689. /**
  690. Partial equality test. If @a weakTest is @true, attributes of this object do not
  691. have to be present if those attributes of @a border are present. If @a weakTest is
  692. @false, the function will fail if an attribute is present in @a border but not
  693. in this object.
  694. */
  695. bool EqPartial(const wxTextAttrBorder& border, bool weakTest = true) const;
  696. /**
  697. Applies the border to this object, but not if the same as @a compareWith.
  698. */
  699. bool Apply(const wxTextAttrBorder& border, const wxTextAttrBorder* compareWith = NULL);
  700. /**
  701. Removes the specified attributes from this object.
  702. */
  703. bool RemoveStyle(const wxTextAttrBorder& attr);
  704. /**
  705. Collects the attributes that are common to a range of content, building up a note of
  706. which attributes are absent in some objects and which clash in some objects.
  707. */
  708. void CollectCommonAttributes(const wxTextAttrBorder& attr, wxTextAttrBorder& clashingAttr, wxTextAttrBorder& absentAttr);
  709. /**
  710. Sets the border style.
  711. */
  712. void SetStyle(int style) { m_borderStyle = style; m_flags |= wxTEXT_BOX_ATTR_BORDER_STYLE; }
  713. /**
  714. Gets the border style.
  715. */
  716. int GetStyle() const { return m_borderStyle; }
  717. /**
  718. Sets the border colour.
  719. */
  720. void SetColour(unsigned long colour) { m_borderColour = colour; m_flags |= wxTEXT_BOX_ATTR_BORDER_COLOUR; }
  721. /**
  722. Sets the border colour.
  723. */
  724. void SetColour(const wxColour& colour) { m_borderColour = colour.GetRGB(); m_flags |= wxTEXT_BOX_ATTR_BORDER_COLOUR; }
  725. /**
  726. Gets the colour as a long.
  727. */
  728. unsigned long GetColourLong() const { return m_borderColour; }
  729. /**
  730. Gets the colour.
  731. */
  732. wxColour GetColour() const { return wxColour(m_borderColour); }
  733. /**
  734. Gets the border width.
  735. */
  736. wxTextAttrDimension& GetWidth() { return m_borderWidth; }
  737. const wxTextAttrDimension& GetWidth() const { return m_borderWidth; }
  738. /**
  739. Sets the border width.
  740. */
  741. void SetWidth(const wxTextAttrDimension& width) { m_borderWidth = width; }
  742. /**
  743. Sets the border width.
  744. */
  745. void SetWidth(int value, wxTextAttrUnits units = wxTEXT_ATTR_UNITS_TENTHS_MM) { SetWidth(wxTextAttrDimension(value, units)); }
  746. /**
  747. True if the border has a valid style.
  748. */
  749. bool HasStyle() const { return (m_flags & wxTEXT_BOX_ATTR_BORDER_STYLE) != 0; }
  750. /**
  751. True if the border has a valid colour.
  752. */
  753. bool HasColour() const { return (m_flags & wxTEXT_BOX_ATTR_BORDER_COLOUR) != 0; }
  754. /**
  755. True if the border has a valid width.
  756. */
  757. bool HasWidth() const { return m_borderWidth.IsValid(); }
  758. /**
  759. True if the border is valid.
  760. */
  761. bool IsValid() const { return HasWidth(); }
  762. /**
  763. Set the valid flag for this border.
  764. */
  765. void MakeValid() { m_borderWidth.SetValid(true); }
  766. /**
  767. True if the border has no attributes set.
  768. */
  769. bool IsDefault() const { return (m_flags == 0); }
  770. /**
  771. Returns the border flags.
  772. */
  773. int GetFlags() const { return m_flags; }
  774. /**
  775. Sets the border flags.
  776. */
  777. void SetFlags(int flags) { m_flags = flags; }
  778. /**
  779. Adds a border flag.
  780. */
  781. void AddFlag(int flag) { m_flags |= flag; }
  782. /**
  783. Removes a border flag.
  784. */
  785. void RemoveFlag(int flag) { m_flags &= ~flag; }
  786. int m_borderStyle;
  787. unsigned long m_borderColour;
  788. wxTextAttrDimension m_borderWidth;
  789. int m_flags;
  790. };
  791. /**
  792. @class wxTextAttrBorders
  793. A class representing a rich text object's borders.
  794. @library{wxrichtext}
  795. @category{richtext}
  796. @see wxRichTextAttr, wxRichTextCtrl, wxRichTextAttrBorder
  797. */
  798. class WXDLLIMPEXP_RICHTEXT wxTextAttrBorders
  799. {
  800. public:
  801. /**
  802. Default constructor.
  803. */
  804. wxTextAttrBorders() { }
  805. /**
  806. Equality operator.
  807. */
  808. bool operator==(const wxTextAttrBorders& borders) const
  809. {
  810. return m_left == borders.m_left && m_right == borders.m_right &&
  811. m_top == borders.m_top && m_bottom == borders.m_bottom;
  812. }
  813. /**
  814. Sets the style of all borders.
  815. */
  816. void SetStyle(int style);
  817. /**
  818. Sets colour of all borders.
  819. */
  820. void SetColour(unsigned long colour);
  821. /**
  822. Sets the colour for all borders.
  823. */
  824. void SetColour(const wxColour& colour);
  825. /**
  826. Sets the width of all borders.
  827. */
  828. void SetWidth(const wxTextAttrDimension& width);
  829. /**
  830. Sets the width of all borders.
  831. */
  832. void SetWidth(int value, wxTextAttrUnits units = wxTEXT_ATTR_UNITS_TENTHS_MM) { SetWidth(wxTextAttrDimension(value, units)); }
  833. /**
  834. Resets all borders.
  835. */
  836. void Reset() { m_left.Reset(); m_right.Reset(); m_top.Reset(); m_bottom.Reset(); }
  837. /**
  838. Partial equality test. If @a weakTest is @true, attributes of this object do not
  839. have to be present if those attributes of @a borders are present. If @a weakTest is
  840. @false, the function will fail if an attribute is present in @a borders but not
  841. in this object.
  842. */
  843. bool EqPartial(const wxTextAttrBorders& borders, bool weakTest = true) const;
  844. /**
  845. Applies border to this object, but not if the same as @a compareWith.
  846. */
  847. bool Apply(const wxTextAttrBorders& borders, const wxTextAttrBorders* compareWith = NULL);
  848. /**
  849. Removes the specified attributes from this object.
  850. */
  851. bool RemoveStyle(const wxTextAttrBorders& attr);
  852. /**
  853. Collects the attributes that are common to a range of content, building up a note of
  854. which attributes are absent in some objects and which clash in some objects.
  855. */
  856. void CollectCommonAttributes(const wxTextAttrBorders& attr, wxTextAttrBorders& clashingAttr, wxTextAttrBorders& absentAttr);
  857. /**
  858. Returns @true if at least one border is valid.
  859. */
  860. bool IsValid() const { return m_left.IsValid() || m_right.IsValid() || m_top.IsValid() || m_bottom.IsValid(); }
  861. /**
  862. Returns @true if no border attributes were set.
  863. */
  864. bool IsDefault() const { return m_left.IsDefault() && m_right.IsDefault() && m_top.IsDefault() && m_bottom.IsDefault(); }
  865. /**
  866. Returns the left border.
  867. */
  868. const wxTextAttrBorder& GetLeft() const { return m_left; }
  869. wxTextAttrBorder& GetLeft() { return m_left; }
  870. /**
  871. Returns the right border.
  872. */
  873. const wxTextAttrBorder& GetRight() const { return m_right; }
  874. wxTextAttrBorder& GetRight() { return m_right; }
  875. /**
  876. Returns the top border.
  877. */
  878. const wxTextAttrBorder& GetTop() const { return m_top; }
  879. wxTextAttrBorder& GetTop() { return m_top; }
  880. /**
  881. Returns the bottom border.
  882. */
  883. const wxTextAttrBorder& GetBottom() const { return m_bottom; }
  884. wxTextAttrBorder& GetBottom() { return m_bottom; }
  885. wxTextAttrBorder m_left, m_right, m_top, m_bottom;
  886. };
  887. /**
  888. @class wxTextBoxAttr
  889. A class representing the box attributes of a rich text object.
  890. @library{wxrichtext}
  891. @category{richtext}
  892. @see wxRichTextAttr, wxRichTextCtrl
  893. */
  894. class WXDLLIMPEXP_RICHTEXT wxTextBoxAttr
  895. {
  896. public:
  897. /**
  898. Default constructor.
  899. */
  900. wxTextBoxAttr() { Init(); }
  901. /**
  902. Copy constructor.
  903. */
  904. wxTextBoxAttr(const wxTextBoxAttr& attr) { Init(); (*this) = attr; }
  905. /**
  906. Initialises this object.
  907. */
  908. void Init() { Reset(); }
  909. /**
  910. Resets this object.
  911. */
  912. void Reset();
  913. // Copy. Unnecessary since we let it do a binary copy
  914. //void Copy(const wxTextBoxAttr& attr);
  915. // Assignment
  916. //void operator= (const wxTextBoxAttr& attr);
  917. /**
  918. Equality test.
  919. */
  920. bool operator== (const wxTextBoxAttr& attr) const;
  921. /**
  922. Partial equality test, ignoring unset attributes. If @a weakTest is @true, attributes of this object do not
  923. have to be present if those attributes of @a attr are present. If @a weakTest is
  924. @false, the function will fail if an attribute is present in @a attr but not
  925. in this object.
  926. */
  927. bool EqPartial(const wxTextBoxAttr& attr, bool weakTest = true) const;
  928. /**
  929. Merges the given attributes. If @a compareWith is non-NULL, then it will be used
  930. to mask out those attributes that are the same in style and @a compareWith, for
  931. situations where we don't want to explicitly set inherited attributes.
  932. */
  933. bool Apply(const wxTextBoxAttr& style, const wxTextBoxAttr* compareWith = NULL);
  934. /**
  935. Collects the attributes that are common to a range of content, building up a note of
  936. which attributes are absent in some objects and which clash in some objects.
  937. */
  938. void CollectCommonAttributes(const wxTextBoxAttr& attr, wxTextBoxAttr& clashingAttr, wxTextBoxAttr& absentAttr);
  939. /**
  940. Removes the specified attributes from this object.
  941. */
  942. bool RemoveStyle(const wxTextBoxAttr& attr);
  943. /**
  944. Sets the flags.
  945. */
  946. void SetFlags(int flags) { m_flags = flags; }
  947. /**
  948. Returns the flags.
  949. */
  950. int GetFlags() const { return m_flags; }
  951. /**
  952. Is this flag present?
  953. */
  954. bool HasFlag(wxTextBoxAttrFlags flag) const { return (m_flags & flag) != 0; }
  955. /**
  956. Removes this flag.
  957. */
  958. void RemoveFlag(wxTextBoxAttrFlags flag) { m_flags &= ~flag; }
  959. /**
  960. Adds this flag.
  961. */
  962. void AddFlag(wxTextBoxAttrFlags flag) { m_flags |= flag; }
  963. /**
  964. Returns @true if no attributes are set.
  965. */
  966. bool IsDefault() const;
  967. /**
  968. Returns the float mode.
  969. */
  970. wxTextBoxAttrFloatStyle GetFloatMode() const { return m_floatMode; }
  971. /**
  972. Sets the float mode.
  973. */
  974. void SetFloatMode(wxTextBoxAttrFloatStyle mode) { m_floatMode = mode; m_flags |= wxTEXT_BOX_ATTR_FLOAT; }
  975. /**
  976. Returns @true if float mode is active.
  977. */
  978. bool HasFloatMode() const { return HasFlag(wxTEXT_BOX_ATTR_FLOAT); }
  979. /**
  980. Returns @true if this object is floating.
  981. */
  982. bool IsFloating() const { return HasFloatMode() && GetFloatMode() != wxTEXT_BOX_ATTR_FLOAT_NONE; }
  983. /**
  984. Returns the clear mode - whether to wrap text after object. Currently unimplemented.
  985. */
  986. wxTextBoxAttrClearStyle GetClearMode() const { return m_clearMode; }
  987. /**
  988. Set the clear mode. Currently unimplemented.
  989. */
  990. void SetClearMode(wxTextBoxAttrClearStyle mode) { m_clearMode = mode; m_flags |= wxTEXT_BOX_ATTR_CLEAR; }
  991. /**
  992. Returns @true if we have a clear flag.
  993. */
  994. bool HasClearMode() const { return HasFlag(wxTEXT_BOX_ATTR_CLEAR); }
  995. /**
  996. Returns the collapse mode - whether to collapse borders.
  997. */
  998. wxTextBoxAttrCollapseMode GetCollapseBorders() const { return m_collapseMode; }
  999. /**
  1000. Sets the collapse mode - whether to collapse borders.
  1001. */
  1002. void SetCollapseBorders(wxTextBoxAttrCollapseMode collapse) { m_collapseMode = collapse; m_flags |= wxTEXT_BOX_ATTR_COLLAPSE_BORDERS; }
  1003. /**
  1004. Returns @true if the collapse borders flag is present.
  1005. */
  1006. bool HasCollapseBorders() const { return HasFlag(wxTEXT_BOX_ATTR_COLLAPSE_BORDERS); }
  1007. /**
  1008. Returns the vertical alignment.
  1009. */
  1010. wxTextBoxAttrVerticalAlignment GetVerticalAlignment() const { return m_verticalAlignment; }
  1011. /**
  1012. Sets the vertical alignment.
  1013. */
  1014. void SetVerticalAlignment(wxTextBoxAttrVerticalAlignment verticalAlignment) { m_verticalAlignment = verticalAlignment; m_flags |= wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT; }
  1015. /**
  1016. Returns @true if a vertical alignment flag is present.
  1017. */
  1018. bool HasVerticalAlignment() const { return HasFlag(wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT); }
  1019. /**
  1020. Returns the margin values.
  1021. */
  1022. wxTextAttrDimensions& GetMargins() { return m_margins; }
  1023. const wxTextAttrDimensions& GetMargins() const { return m_margins; }
  1024. /**
  1025. Returns the left margin.
  1026. */
  1027. wxTextAttrDimension& GetLeftMargin() { return m_margins.m_left; }
  1028. const wxTextAttrDimension& GetLeftMargin() const { return m_margins.m_left; }
  1029. /**
  1030. Returns the right margin.
  1031. */
  1032. wxTextAttrDimension& GetRightMargin() { return m_margins.m_right; }
  1033. const wxTextAttrDimension& GetRightMargin() const { return m_margins.m_right; }
  1034. /**
  1035. Returns the top margin.
  1036. */
  1037. wxTextAttrDimension& GetTopMargin() { return m_margins.m_top; }
  1038. const wxTextAttrDimension& GetTopMargin() const { return m_margins.m_top; }
  1039. /**
  1040. Returns the bottom margin.
  1041. */
  1042. wxTextAttrDimension& GetBottomMargin() { return m_margins.m_bottom; }
  1043. const wxTextAttrDimension& GetBottomMargin() const { return m_margins.m_bottom; }
  1044. /**
  1045. Returns the position.
  1046. */
  1047. wxTextAttrDimensions& GetPosition() { return m_position; }
  1048. const wxTextAttrDimensions& GetPosition() const { return m_position; }
  1049. /**
  1050. Returns the left position.
  1051. */
  1052. wxTextAttrDimension& GetLeft() { return m_position.m_left; }
  1053. const wxTextAttrDimension& GetLeft() const { return m_position.m_left; }
  1054. /**
  1055. Returns the right position.
  1056. */
  1057. wxTextAttrDimension& GetRight() { return m_position.m_right; }
  1058. const wxTextAttrDimension& GetRight() const { return m_position.m_right; }
  1059. /**
  1060. Returns the top position.
  1061. */
  1062. wxTextAttrDimension& GetTop() { return m_position.m_top; }
  1063. const wxTextAttrDimension& GetTop() const { return m_position.m_top; }
  1064. /**
  1065. Returns the bottom position.
  1066. */
  1067. wxTextAttrDimension& GetBottom() { return m_position.m_bottom; }
  1068. const wxTextAttrDimension& GetBottom() const { return m_position.m_bottom; }
  1069. /**
  1070. Returns the padding values.
  1071. */
  1072. wxTextAttrDimensions& GetPadding() { return m_padding; }
  1073. const wxTextAttrDimensions& GetPadding() const { return m_padding; }
  1074. /**
  1075. Returns the left padding value.
  1076. */
  1077. wxTextAttrDimension& GetLeftPadding() { return m_padding.m_left; }
  1078. const wxTextAttrDimension& GetLeftPadding() const { return m_padding.m_left; }
  1079. /**
  1080. Returns the right padding value.
  1081. */
  1082. wxTextAttrDimension& GetRightPadding() { return m_padding.m_right; }
  1083. const wxTextAttrDimension& GetRightPadding() const { return m_padding.m_right; }
  1084. /**
  1085. Returns the top padding value.
  1086. */
  1087. wxTextAttrDimension& GetTopPadding() { return m_padding.m_top; }
  1088. const wxTextAttrDimension& GetTopPadding() const { return m_padding.m_top; }
  1089. /**
  1090. Returns the bottom padding value.
  1091. */
  1092. wxTextAttrDimension& GetBottomPadding() { return m_padding.m_bottom; }
  1093. const wxTextAttrDimension& GetBottomPadding() const { return m_padding.m_bottom; }
  1094. /**
  1095. Returns the borders.
  1096. */
  1097. wxTextAttrBorders& GetBorder() { return m_border; }
  1098. const wxTextAttrBorders& GetBorder() const { return m_border; }
  1099. /**
  1100. Returns the left border.
  1101. */
  1102. wxTextAttrBorder& GetLeftBorder() { return m_border.m_left; }
  1103. const wxTextAttrBorder& GetLeftBorder() const { return m_border.m_left; }
  1104. /**
  1105. Returns the top border.
  1106. */
  1107. wxTextAttrBorder& GetTopBorder() { return m_border.m_top; }
  1108. const wxTextAttrBorder& GetTopBorder() const { return m_border.m_top; }
  1109. /**
  1110. Returns the right border.
  1111. */
  1112. wxTextAttrBorder& GetRightBorder() { return m_border.m_right; }
  1113. const wxTextAttrBorder& GetRightBorder() const { return m_border.m_right; }
  1114. /**
  1115. Returns the bottom border.
  1116. */
  1117. wxTextAttrBorder& GetBottomBorder() { return m_border.m_bottom; }
  1118. const wxTextAttrBorder& GetBottomBorder() const { return m_border.m_bottom; }
  1119. /**
  1120. Returns the outline.
  1121. */
  1122. wxTextAttrBorders& GetOutline() { return m_outline; }
  1123. const wxTextAttrBorders& GetOutline() const { return m_outline; }
  1124. /**
  1125. Returns the left outline.
  1126. */
  1127. wxTextAttrBorder& GetLeftOutline() { return m_outline.m_left; }
  1128. const wxTextAttrBorder& GetLeftOutline() const { return m_outline.m_left; }
  1129. /**
  1130. Returns the top outline.
  1131. */
  1132. wxTextAttrBorder& GetTopOutline() { return m_outline.m_top; }
  1133. const wxTextAttrBorder& GetTopOutline() const { return m_outline.m_top; }
  1134. /**
  1135. Returns the right outline.
  1136. */
  1137. wxTextAttrBorder& GetRightOutline() { return m_outline.m_right; }
  1138. const wxTextAttrBorder& GetRightOutline() const { return m_outline.m_right; }
  1139. /**
  1140. Returns the bottom outline.
  1141. */
  1142. wxTextAttrBorder& GetBottomOutline() { return m_outline.m_bottom; }
  1143. const wxTextAttrBorder& GetBottomOutline() const { return m_outline.m_bottom; }
  1144. /**
  1145. Returns the object size.
  1146. */
  1147. wxTextAttrSize& GetSize() { return m_size; }
  1148. const wxTextAttrSize& GetSize() const { return m_size; }
  1149. /**
  1150. Returns the object minimum size.
  1151. */
  1152. wxTextAttrSize& GetMinSize() { return m_minSize; }
  1153. const wxTextAttrSize& GetMinSize() const { return m_minSize; }
  1154. /**
  1155. Returns the object maximum size.
  1156. */
  1157. wxTextAttrSize& GetMaxSize() { return m_maxSize; }
  1158. const wxTextAttrSize& GetMaxSize() const { return m_maxSize; }
  1159. /**
  1160. Sets the object size.
  1161. */
  1162. void SetSize(const wxTextAttrSize& sz) { m_size = sz; }
  1163. /**
  1164. Sets the object minimum size.
  1165. */
  1166. void SetMinSize(const wxTextAttrSize& sz) { m_minSize = sz; }
  1167. /**
  1168. Sets the object maximum size.
  1169. */
  1170. void SetMaxSize(const wxTextAttrSize& sz) { m_maxSize = sz; }
  1171. /**
  1172. Returns the object width.
  1173. */
  1174. wxTextAttrDimension& GetWidth() { return m_size.m_width; }
  1175. const wxTextAttrDimension& GetWidth() const { return m_size.m_width; }
  1176. /**
  1177. Returns the object height.
  1178. */
  1179. wxTextAttrDimension& GetHeight() { return m_size.m_height; }
  1180. const wxTextAttrDimension& GetHeight() const { return m_size.m_height; }
  1181. /**
  1182. Returns the box style name.
  1183. */
  1184. const wxString& GetBoxStyleName() const { return m_boxStyleName; }
  1185. /**
  1186. Sets the box style name.
  1187. */
  1188. void SetBoxStyleName(const wxString& name) { m_boxStyleName = name; AddFlag(wxTEXT_BOX_ATTR_BOX_STYLE_NAME); }
  1189. /**
  1190. Returns @true if the box style name is present.
  1191. */
  1192. bool HasBoxStyleName() const { return HasFlag(wxTEXT_BOX_ATTR_BOX_STYLE_NAME); }
  1193. public:
  1194. int m_flags;
  1195. wxTextAttrDimensions m_margins;
  1196. wxTextAttrDimensions m_padding;
  1197. wxTextAttrDimensions m_position;
  1198. wxTextAttrSize m_size;
  1199. wxTextAttrSize m_minSize;
  1200. wxTextAttrSize m_maxSize;
  1201. wxTextAttrBorders m_border;
  1202. wxTextAttrBorders m_outline;
  1203. wxTextBoxAttrFloatStyle m_floatMode;
  1204. wxTextBoxAttrClearStyle m_clearMode;
  1205. wxTextBoxAttrCollapseMode m_collapseMode;
  1206. wxTextBoxAttrVerticalAlignment m_verticalAlignment;
  1207. wxString m_boxStyleName;
  1208. };
  1209. /**
  1210. @class wxRichTextAttr
  1211. A class representing enhanced attributes for rich text objects.
  1212. This adds a wxTextBoxAttr member to the basic wxTextAttr class.
  1213. @library{wxrichtext}
  1214. @category{richtext}
  1215. @see wxRichTextAttr, wxTextBoxAttr, wxRichTextCtrl
  1216. */
  1217. class WXDLLIMPEXP_RICHTEXT wxRichTextAttr: public wxTextAttr
  1218. {
  1219. public:
  1220. /**
  1221. Constructor taking a wxTextAttr.
  1222. */
  1223. wxRichTextAttr(const wxTextAttr& attr) { wxTextAttr::Copy(attr); }
  1224. /**
  1225. Copy constructor.
  1226. */
  1227. wxRichTextAttr(const wxRichTextAttr& attr): wxTextAttr() { Copy(attr); }
  1228. /**
  1229. Default constructor.
  1230. */
  1231. wxRichTextAttr() {}
  1232. /**
  1233. Copy function.
  1234. */
  1235. void Copy(const wxRichTextAttr& attr);
  1236. /**
  1237. Assignment operator.
  1238. */
  1239. void operator=(const wxRichTextAttr& attr) { Copy(attr); }
  1240. /**
  1241. Assignment operator.
  1242. */
  1243. void operator=(const wxTextAttr& attr) { wxTextAttr::Copy(attr); }
  1244. /**
  1245. Equality test.
  1246. */
  1247. bool operator==(const wxRichTextAttr& attr) const;
  1248. /**
  1249. Partial equality test. If @a weakTest is @true, attributes of this object do not
  1250. have to be present if those attributes of @a attr are present. If @a weakTest is
  1251. @false, the function will fail if an attribute is present in @a attr but not
  1252. in this object.
  1253. */
  1254. bool EqPartial(const wxRichTextAttr& attr, bool weakTest = true) const;
  1255. /**
  1256. Merges the given attributes. If @a compareWith
  1257. is non-NULL, then it will be used to mask out those attributes that are the same in style
  1258. and @a compareWith, for situations where we don't want to explicitly set inherited attributes.
  1259. */
  1260. bool Apply(const wxRichTextAttr& style, const wxRichTextAttr* compareWith = NULL);
  1261. /**
  1262. Collects the attributes that are common to a range of content, building up a note of
  1263. which attributes are absent in some objects and which clash in some objects.
  1264. */
  1265. void CollectCommonAttributes(const wxRichTextAttr& attr, wxRichTextAttr& clashingAttr, wxRichTextAttr& absentAttr);
  1266. /**
  1267. Removes the specified attributes from this object.
  1268. */
  1269. bool RemoveStyle(const wxRichTextAttr& attr);
  1270. /**
  1271. Returns the text box attributes.
  1272. */
  1273. wxTextBoxAttr& GetTextBoxAttr() { return m_textBoxAttr; }
  1274. const wxTextBoxAttr& GetTextBoxAttr() const { return m_textBoxAttr; }
  1275. /**
  1276. Set the text box attributes.
  1277. */
  1278. void SetTextBoxAttr(const wxTextBoxAttr& attr) { m_textBoxAttr = attr; }
  1279. /**
  1280. Returns @true if no attributes are set.
  1281. */
  1282. bool IsDefault() const { return (GetFlags() == 0) && m_textBoxAttr.IsDefault(); }
  1283. wxTextBoxAttr m_textBoxAttr;
  1284. };
  1285. WX_DECLARE_USER_EXPORTED_OBJARRAY(wxRichTextAttr, wxRichTextAttrArray, WXDLLIMPEXP_RICHTEXT);
  1286. WX_DECLARE_USER_EXPORTED_OBJARRAY(wxVariant, wxRichTextVariantArray, WXDLLIMPEXP_RICHTEXT);
  1287. WX_DECLARE_USER_EXPORTED_OBJARRAY(wxRect, wxRichTextRectArray, WXDLLIMPEXP_RICHTEXT);
  1288. /**
  1289. @class wxRichTextProperties
  1290. A simple property class using wxVariants. This is used to give each rich text object the
  1291. ability to store custom properties that can be used by the application.
  1292. @library{wxrichtext}
  1293. @category{richtext}
  1294. @see wxRichTextBuffer, wxRichTextObject, wxRichTextCtrl
  1295. */
  1296. class WXDLLIMPEXP_RICHTEXT wxRichTextProperties: public wxObject
  1297. {
  1298. DECLARE_DYNAMIC_CLASS(wxRichTextProperties)
  1299. public:
  1300. /**
  1301. Default constructor.
  1302. */
  1303. wxRichTextProperties() {}
  1304. /**
  1305. Copy constructor.
  1306. */
  1307. wxRichTextProperties(const wxRichTextProperties& props): wxObject() { Copy(props); }
  1308. /**
  1309. Assignment operator.
  1310. */
  1311. void operator=(const wxRichTextProperties& props) { Copy(props); }
  1312. /**
  1313. Equality operator.
  1314. */
  1315. bool operator==(const wxRichTextProperties& props) const;
  1316. /**
  1317. Copies from @a props.
  1318. */
  1319. void Copy(const wxRichTextProperties& props) { m_properties = props.m_properties; }
  1320. /**
  1321. Returns the variant at the given index.
  1322. */
  1323. const wxVariant& operator[](size_t idx) const { return m_properties[idx]; }
  1324. /**
  1325. Returns the variant at the given index.
  1326. */
  1327. wxVariant& operator[](size_t idx) { return m_properties[idx]; }
  1328. /**
  1329. Clears the properties.
  1330. */
  1331. void Clear() { m_properties.Clear(); }
  1332. /**
  1333. Returns the array of variants implementing the properties.
  1334. */
  1335. const wxRichTextVariantArray& GetProperties() const { return m_properties; }
  1336. /**
  1337. Returns the array of variants implementing the properties.
  1338. */
  1339. wxRichTextVariantArray& GetProperties() { return m_properties; }
  1340. /**
  1341. Sets the array of variants.
  1342. */
  1343. void SetProperties(const wxRichTextVariantArray& props) { m_properties = props; }
  1344. /**
  1345. Returns all the property names.
  1346. */
  1347. wxArrayString GetPropertyNames() const;
  1348. /**
  1349. Returns a count of the properties.
  1350. */
  1351. size_t GetCount() const { return m_properties.GetCount(); }
  1352. /**
  1353. Returns @true if the given property is found.
  1354. */
  1355. bool HasProperty(const wxString& name) const { return Find(name) != -1; }
  1356. /**
  1357. Finds the given property.
  1358. */
  1359. int Find(const wxString& name) const;
  1360. /**
  1361. Removes the given property.
  1362. */
  1363. bool Remove(const wxString& name);
  1364. /**
  1365. Gets the property variant by name.
  1366. */
  1367. const wxVariant& GetProperty(const wxString& name) const;
  1368. /**
  1369. Finds or creates a property with the given name, returning a pointer to the variant.
  1370. */
  1371. wxVariant* FindOrCreateProperty(const wxString& name);
  1372. /**
  1373. Gets the value of the named property as a string.
  1374. */
  1375. wxString GetPropertyString(const wxString& name) const;
  1376. /**
  1377. Gets the value of the named property as a long integer.
  1378. */
  1379. long GetPropertyLong(const wxString& name) const;
  1380. /**
  1381. Gets the value of the named property as a boolean.
  1382. */
  1383. bool GetPropertyBool(const wxString& name) const;
  1384. /**
  1385. Gets the value of the named property as a double.
  1386. */
  1387. double GetPropertyDouble(const wxString& name) const;
  1388. /**
  1389. Sets the property by passing a variant which contains a name and value.
  1390. */
  1391. void SetProperty(const wxVariant& variant);
  1392. /**
  1393. Sets a property by name and variant.
  1394. */
  1395. void SetProperty(const wxString& name, const wxVariant& variant);
  1396. /**
  1397. Sets a property by name and string value.
  1398. */
  1399. void SetProperty(const wxString& name, const wxString& value);
  1400. /**
  1401. Sets a property by name and wxChar* value.
  1402. */
  1403. void SetProperty(const wxString& name, const wxChar* value) { SetProperty(name, wxString(value)); }
  1404. /**
  1405. Sets property by name and long integer value.
  1406. */
  1407. void SetProperty(const wxString& name, long value);
  1408. /**
  1409. Sets property by name and double value.
  1410. */
  1411. void SetProperty(const wxString& name, double value);
  1412. /**
  1413. Sets property by name and boolean value.
  1414. */
  1415. void SetProperty(const wxString& name, bool value);
  1416. /**
  1417. Removes the given properties from these properties.
  1418. */
  1419. void RemoveProperties(const wxRichTextProperties& properties);
  1420. /**
  1421. Merges the given properties with these properties.
  1422. */
  1423. void MergeProperties(const wxRichTextProperties& properties);
  1424. protected:
  1425. wxRichTextVariantArray m_properties;
  1426. };
  1427. /**
  1428. @class wxRichTextFontTable
  1429. Manages quick access to a pool of fonts for rendering rich text.
  1430. @library{wxrichtext}
  1431. @category{richtext}
  1432. @see wxRichTextBuffer, wxRichTextCtrl
  1433. */
  1434. class WXDLLIMPEXP_RICHTEXT wxRichTextFontTable: public wxObject
  1435. {
  1436. public:
  1437. /**
  1438. Default constructor.
  1439. */
  1440. wxRichTextFontTable();
  1441. /**
  1442. Copy constructor.
  1443. */
  1444. wxRichTextFontTable(const wxRichTextFontTable& table);
  1445. virtual ~wxRichTextFontTable();
  1446. /**
  1447. Returns @true if the font table is valid.
  1448. */
  1449. bool IsOk() const { return m_refData != NULL; }
  1450. /**
  1451. Finds a font for the given attribute object.
  1452. */
  1453. wxFont FindFont(const wxRichTextAttr& fontSpec);
  1454. /**
  1455. Clears the font table.
  1456. */
  1457. void Clear();
  1458. /**
  1459. Assignment operator.
  1460. */
  1461. void operator= (const wxRichTextFontTable& table);
  1462. /**
  1463. Equality operator.
  1464. */
  1465. bool operator == (const wxRichTextFontTable& table) const;
  1466. /**
  1467. Inequality operator.
  1468. */
  1469. bool operator != (const wxRichTextFontTable& table) const { return !(*this == table); }
  1470. /**
  1471. Set the font scale factor.
  1472. */
  1473. void SetFontScale(double fontScale);
  1474. protected:
  1475. double m_fontScale;
  1476. DECLARE_DYNAMIC_CLASS(wxRichTextFontTable)
  1477. };
  1478. /**
  1479. @class wxRichTextRange
  1480. This stores beginning and end positions for a range of data.
  1481. @library{wxrichtext}
  1482. @category{richtext}
  1483. @see wxRichTextBuffer, wxRichTextCtrl
  1484. */
  1485. class WXDLLIMPEXP_RICHTEXT wxRichTextRange
  1486. {
  1487. public:
  1488. // Constructors
  1489. /**
  1490. Default constructor.
  1491. */
  1492. wxRichTextRange() { m_start = 0; m_end = 0; }
  1493. /**
  1494. Constructor taking start and end positions.
  1495. */
  1496. wxRichTextRange(long start, long end) { m_start = start; m_end = end; }
  1497. /**
  1498. Copy constructor.
  1499. */
  1500. wxRichTextRange(const wxRichTextRange& range) { m_start = range.m_start; m_end = range.m_end; }
  1501. ~wxRichTextRange() {}
  1502. /**
  1503. Assigns @a range to this range.
  1504. */
  1505. void operator =(const wxRichTextRange& range) { m_start = range.m_start; m_end = range.m_end; }
  1506. /**
  1507. Equality operator. Returns @true if @a range is the same as this range.
  1508. */
  1509. bool operator ==(const wxRichTextRange& range) const { return (m_start == range.m_start && m_end == range.m_end); }
  1510. /**
  1511. Inequality operator.
  1512. */
  1513. bool operator !=(const wxRichTextRange& range) const { return (m_start != range.m_start || m_end != range.m_end); }
  1514. /**
  1515. Subtracts a range from this range.
  1516. */
  1517. wxRichTextRange operator -(const wxRichTextRange& range) const { return wxRichTextRange(m_start - range.m_start, m_end - range.m_end); }
  1518. /**
  1519. Adds a range to this range.
  1520. */
  1521. wxRichTextRange operator +(const wxRichTextRange& range) const { return wxRichTextRange(m_start + range.m_start, m_end + range.m_end); }
  1522. /**
  1523. Sets the range start and end positions.
  1524. */
  1525. void SetRange(long start, long end) { m_start = start; m_end = end; }
  1526. /**
  1527. Sets the start position.
  1528. */
  1529. void SetStart(long start) { m_start = start; }
  1530. /**
  1531. Returns the start position.
  1532. */
  1533. long GetStart() const { return m_start; }
  1534. /**
  1535. Sets the end position.
  1536. */
  1537. void SetEnd(long end) { m_end = end; }
  1538. /**
  1539. Gets the end position.
  1540. */
  1541. long GetEnd() const { return m_end; }
  1542. /**
  1543. Returns true if this range is completely outside @a range.
  1544. */
  1545. bool IsOutside(const wxRichTextRange& range) const { return range.m_start > m_end || range.m_end < m_start; }
  1546. /**
  1547. Returns true if this range is completely within @a range.
  1548. */
  1549. bool IsWithin(const wxRichTextRange& range) const { return m_start >= range.m_start && m_end <= range.m_end; }
  1550. /**
  1551. Returns true if @a pos was within the range. Does not match if the range is empty.
  1552. */
  1553. bool Contains(long pos) const { return pos >= m_start && pos <= m_end ; }
  1554. /**
  1555. Limit this range to be within @a range.
  1556. */
  1557. bool LimitTo(const wxRichTextRange& range) ;
  1558. /**
  1559. Gets the length of the range.
  1560. */
  1561. long GetLength() const { return m_end - m_start + 1; }
  1562. /**
  1563. Swaps the start and end.
  1564. */
  1565. void Swap() { long tmp = m_start; m_start = m_end; m_end = tmp; }
  1566. /**
  1567. Converts the API-standard range, whose end is one past the last character in
  1568. the range, to the internal form, which uses the first and last character
  1569. positions of the range. In other words, one is subtracted from the end position.
  1570. (n, n) is the range of a single character.
  1571. */
  1572. wxRichTextRange ToInternal() const { return wxRichTextRange(m_start, m_end-1); }
  1573. /**
  1574. Converts the internal range, which uses the first and last character positions
  1575. of the range, to the API-standard range, whose end is one past the last
  1576. character in the range. In other words, one is added to the end position.
  1577. (n, n+1) is the range of a single character.
  1578. */
  1579. wxRichTextRange FromInternal() const { return wxRichTextRange(m_start, m_end+1); }
  1580. protected:
  1581. long m_start;
  1582. long m_end;
  1583. };
  1584. WX_DECLARE_USER_EXPORTED_OBJARRAY(wxRichTextRange, wxRichTextRangeArray, WXDLLIMPEXP_RICHTEXT);
  1585. #define wxRICHTEXT_ALL wxRichTextRange(-2, -2)
  1586. #define wxRICHTEXT_NONE wxRichTextRange(-1, -1)
  1587. #define wxRICHTEXT_NO_SELECTION wxRichTextRange(-2, -2)
  1588. /**
  1589. @class wxRichTextSelection
  1590. Stores selection information. The selection does not have to be contiguous, though currently non-contiguous
  1591. selections are only supported for a range of table cells (a geometric block of cells can consist
  1592. of a set of non-contiguous positions).
  1593. The selection consists of an array of ranges, and the container that is the context for the selection. It
  1594. follows that a single selection object can only represent ranges with the same parent container.
  1595. @library{wxrichtext}
  1596. @category{richtext}
  1597. @see wxRichTextBuffer, wxRichTextCtrl
  1598. */
  1599. class WXDLLIMPEXP_RICHTEXT wxRichTextSelection
  1600. {
  1601. public:
  1602. /**
  1603. Copy constructor.
  1604. */
  1605. wxRichTextSelection(const wxRichTextSelection& sel) { Copy(sel); }
  1606. /**
  1607. Creates a selection from a range and a container.
  1608. */
  1609. wxRichTextSelection(const wxRichTextRange& range, wxRichTextParagraphLayoutBox* container) { m_ranges.Add(range); m_container = container; }
  1610. /**
  1611. Default constructor.
  1612. */
  1613. wxRichTextSelection() { Reset(); }
  1614. /**
  1615. Resets the selection.
  1616. */
  1617. void Reset() { m_ranges.Clear(); m_container = NULL; }
  1618. /**
  1619. Sets the selection.
  1620. */
  1621. void Set(const wxRichTextRange& range, wxRichTextParagraphLayoutBox* container)
  1622. { m_ranges.Clear(); m_ranges.Add(range); m_container = container; }
  1623. /**
  1624. Adds a range to the selection.
  1625. */
  1626. void Add(const wxRichTextRange& range)
  1627. { m_ranges.Add(range); }
  1628. /**
  1629. Sets the selections from an array of ranges and a container object.
  1630. */
  1631. void Set(const wxRichTextRangeArray& ranges, wxRichTextParagraphLayoutBox* container)
  1632. { m_ranges = ranges; m_container = container; }
  1633. /**
  1634. Copies from @a sel.
  1635. */
  1636. void Copy(const wxRichTextSelection& sel)
  1637. { m_ranges = sel.m_ranges; m_container = sel.m_container; }
  1638. /**
  1639. Assignment operator.
  1640. */
  1641. void operator=(const wxRichTextSelection& sel) { Copy(sel); }
  1642. /**
  1643. Equality operator.
  1644. */
  1645. bool operator==(const wxRichTextSelection& sel) const;
  1646. /**
  1647. Index operator.
  1648. */
  1649. wxRichTextRange operator[](size_t i) const { return GetRange(i); }
  1650. /**
  1651. Returns the selection ranges.
  1652. */
  1653. wxRichTextRangeArray& GetRanges() { return m_ranges; }
  1654. /**
  1655. Returns the selection ranges.
  1656. */
  1657. const wxRichTextRangeArray& GetRanges() const { return m_ranges; }
  1658. /**
  1659. Sets the selection ranges.
  1660. */
  1661. void SetRanges(const wxRichTextRangeArray& ranges) { m_ranges = ranges; }
  1662. /**
  1663. Returns the number of ranges in the selection.
  1664. */
  1665. size_t GetCount() const { return m_ranges.GetCount(); }
  1666. /**
  1667. Returns the range at the given index.
  1668. */
  1669. wxRichTextRange GetRange(size_t i) const { return m_ranges[i]; }
  1670. /**
  1671. Returns the first range if there is one, otherwise wxRICHTEXT_NO_SELECTION.
  1672. */
  1673. wxRichTextRange GetRange() const { return (m_ranges.GetCount() > 0) ? (m_ranges[0]) : wxRICHTEXT_NO_SELECTION; }
  1674. /**
  1675. Sets a single range.
  1676. */
  1677. void SetRange(const wxRichTextRange& range) { m_ranges.Clear(); m_ranges.Add(range); }
  1678. /**
  1679. Returns the container for which the selection is valid.
  1680. */
  1681. wxRichTextParagraphLayoutBox* GetContainer() const { return m_container; }
  1682. /**
  1683. Sets the container for which the selection is valid.
  1684. */
  1685. void SetContainer(wxRichTextParagraphLayoutBox* container) { m_container = container; }
  1686. /**
  1687. Returns @true if the selection is valid.
  1688. */
  1689. bool IsValid() const { return m_ranges.GetCount() > 0 && GetContainer(); }
  1690. /**
  1691. Returns the selection appropriate to the specified object, if any; returns an empty array if none
  1692. at the level of the object's container.
  1693. */
  1694. wxRichTextRangeArray GetSelectionForObject(wxRichTextObject* obj) const;
  1695. /**
  1696. Returns @true if the given position is within the selection.
  1697. */
  1698. bool WithinSelection(long pos, wxRichTextObject* obj) const;
  1699. /**
  1700. Returns @true if the given position is within the selection.
  1701. */
  1702. bool WithinSelection(long pos) const { return WithinSelection(pos, m_ranges); }
  1703. /**
  1704. Returns @true if the given position is within the selection range.
  1705. */
  1706. static bool WithinSelection(long pos, const wxRichTextRangeArray& ranges);
  1707. /**
  1708. Returns @true if the given range is within the selection range.
  1709. */
  1710. static bool WithinSelection(const wxRichTextRange& range, const wxRichTextRangeArray& ranges);
  1711. wxRichTextRangeArray m_ranges;
  1712. wxRichTextParagraphLayoutBox* m_container;
  1713. };
  1714. /**
  1715. @class wxRichTextDrawingContext
  1716. A class for passing information to drawing and measuring functions.
  1717. @library{wxrichtext}
  1718. @category{richtext}
  1719. @see wxRichTextBuffer, wxRichTextCtrl
  1720. */
  1721. class WXDLLIMPEXP_RICHTEXT wxRichTextDrawingContext: public wxObject
  1722. {
  1723. DECLARE_CLASS(wxRichTextDrawingContext)
  1724. public:
  1725. /**
  1726. Pass the buffer to the context so the context can retrieve information
  1727. such as virtual attributes.
  1728. */
  1729. wxRichTextDrawingContext(wxRichTextBuffer* buffer);
  1730. void Init() { m_buffer = NULL; m_enableVirtualAttributes = true; }
  1731. /**
  1732. Does this object have virtual attributes?
  1733. Virtual attributes can be provided for visual cues without
  1734. affecting the actual styling.
  1735. */
  1736. bool HasVirtualAttributes(wxRichTextObject* obj) const;
  1737. /**
  1738. Returns the virtual attributes for this object.
  1739. Virtual attributes can be provided for visual cues without
  1740. affecting the actual styling.
  1741. */
  1742. wxRichTextAttr GetVirtualAttributes(wxRichTextObject* obj) const;
  1743. /**
  1744. Applies any virtual attributes relevant to this object.
  1745. */
  1746. bool ApplyVirtualAttributes(wxRichTextAttr& attr, wxRichTextObject* obj) const;
  1747. /**
  1748. Gets the count for mixed virtual attributes for individual positions within the object.
  1749. For example, individual characters within a text object may require special highlighting.
  1750. */
  1751. int GetVirtualSubobjectAttributesCount(wxRichTextObject* obj) const;
  1752. /**
  1753. Gets the mixed virtual attributes for individual positions within the object.
  1754. For example, individual characters within a text object may require special highlighting.
  1755. The function is passed the count returned by GetVirtualSubobjectAttributesCount.
  1756. */
  1757. int GetVirtualSubobjectAttributes(wxRichTextObject* obj, wxArrayInt& positions, wxRichTextAttrArray& attributes) const;
  1758. /**
  1759. Do we have virtual text for this object? Virtual text allows an application
  1760. to replace characters in an object for editing and display purposes, for example
  1761. for highlighting special characters.
  1762. */
  1763. bool HasVirtualText(const wxRichTextPlainText* obj) const;
  1764. /**
  1765. Gets the virtual text for this object.
  1766. */
  1767. bool GetVirtualText(const wxRichTextPlainText* obj, wxString& text) const;
  1768. /**
  1769. Enables virtual attribute processing.
  1770. */
  1771. void EnableVirtualAttributes(bool b) { m_enableVirtualAttributes = b; }
  1772. /**
  1773. Returns @true if virtual attribute processing is enabled.
  1774. */
  1775. bool GetVirtualAttributesEnabled() const { return m_enableVirtualAttributes; }
  1776. wxRichTextBuffer* m_buffer;
  1777. bool m_enableVirtualAttributes;
  1778. };
  1779. /**
  1780. @class wxRichTextObject
  1781. This is the base for drawable rich text objects.
  1782. @library{wxrichtext}
  1783. @category{richtext}
  1784. @see wxRichTextBuffer, wxRichTextCtrl
  1785. */
  1786. class WXDLLIMPEXP_RICHTEXT wxRichTextObject: public wxObject
  1787. {
  1788. DECLARE_CLASS(wxRichTextObject)
  1789. public:
  1790. /**
  1791. Constructor, taking an optional parent pointer.
  1792. */
  1793. wxRichTextObject(wxRichTextObject* parent = NULL);
  1794. virtual ~wxRichTextObject();
  1795. // Overridables
  1796. /**
  1797. Draw the item, within the given range. Some objects may ignore the range (for
  1798. example paragraphs) while others must obey it (lines, to implement wrapping)
  1799. */
  1800. virtual bool Draw(wxDC& dc, wxRichTextDrawingContext& context, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style) = 0;
  1801. /**
  1802. Lay the item out at the specified position with the given size constraint.
  1803. Layout must set the cached size. @rect is the available space for the object,
  1804. and @a parentRect is the container that is used to determine a relative size
  1805. or position (for example if a text box must be 50% of the parent text box).
  1806. */
  1807. virtual bool Layout(wxDC& dc, wxRichTextDrawingContext& context, const wxRect& rect, const wxRect& parentRect, int style) = 0;
  1808. /**
  1809. Hit-testing: returns a flag indicating hit test details, plus
  1810. information about position. @a contextObj is returned to specify what object
  1811. position is relevant to, since otherwise there's an ambiguity.
  1812. @ obj might not be a child of @a contextObj, since we may be referring to the container itself
  1813. if we have no hit on a child - for example if we click outside an object.
  1814. The function puts the position in @a textPosition if one is found.
  1815. @a pt is in logical units (a zero y position is at the beginning of the buffer).
  1816. Pass wxRICHTEXT_HITTEST_NO_NESTED_OBJECTS if you only want to consider objects
  1817. directly under the object you are calling HitTest on. Otherwise, it will recurse
  1818. and potentially find a nested object.
  1819. @return One of the ::wxRichTextHitTestFlags values.
  1820. */
  1821. virtual int HitTest(wxDC& dc, wxRichTextDrawingContext& context, const wxPoint& pt, long& textPosition, wxRichTextObject** obj, wxRichTextObject** contextObj, int flags = 0);
  1822. /**
  1823. Finds the absolute position and row height for the given character position.
  1824. */
  1825. virtual bool FindPosition(wxDC& WXUNUSED(dc), wxRichTextDrawingContext& WXUNUSED(context), long WXUNUSED(index), wxPoint& WXUNUSED(pt), int* WXUNUSED(height), bool WXUNUSED(forceLineStart)) { return false; }
  1826. /**
  1827. Returns the best size, i.e. the ideal starting size for this object irrespective
  1828. of available space. For a short text string, it will be the size that exactly encloses
  1829. the text. For a longer string, it might use the parent width for example.
  1830. */
  1831. virtual wxSize GetBestSize() const { return m_size; }
  1832. /**
  1833. Returns the object size for the given range. Returns @false if the range
  1834. is invalid for this object.
  1835. */
  1836. virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, wxRichTextDrawingContext& context, int flags, const wxPoint& position = wxPoint(0,0), const wxSize& parentSize = wxDefaultSize, wxArrayInt* partialExtents = NULL) const = 0;
  1837. /**
  1838. Do a split from @a pos, returning an object containing the second part, and setting
  1839. the first part in 'this'.
  1840. */
  1841. virtual wxRichTextObject* DoSplit(long WXUNUSED(pos)) { return NULL; }
  1842. /**
  1843. Calculates the range of the object. By default, guess that the object is 1 unit long.
  1844. */
  1845. virtual void CalculateRange(long start, long& end) { end = start ; m_range.SetRange(start, end); }
  1846. /**
  1847. Deletes the given range.
  1848. */
  1849. virtual bool DeleteRange(const wxRichTextRange& WXUNUSED(range)) { return false; }
  1850. /**
  1851. Returns @true if the object is empty.
  1852. */
  1853. virtual bool IsEmpty() const { return false; }
  1854. /**
  1855. Returns @true if this class of object is floatable.
  1856. */
  1857. virtual bool IsFloatable() const { return false; }
  1858. /**
  1859. Returns @true if this object is currently floating.
  1860. */
  1861. virtual bool IsFloating() const { return GetAttributes().GetTextBoxAttr().IsFloating(); }
  1862. /**
  1863. Returns the floating direction.
  1864. */
  1865. virtual int GetFloatDirection() const { return GetAttributes().GetTextBoxAttr().GetFloatMode(); }
  1866. /**
  1867. Returns any text in this object for the given range.
  1868. */
  1869. virtual wxString GetTextForRange(const wxRichTextRange& WXUNUSED(range)) const { return wxEmptyString; }
  1870. /**
  1871. Returns @true if this object can merge itself with the given one.
  1872. */
  1873. virtual bool CanMerge(wxRichTextObject* WXUNUSED(object), wxRichTextDrawingContext& WXUNUSED(context)) const { return false; }
  1874. /**
  1875. Returns @true if this object merged itself with the given one.
  1876. The calling code will then delete the given object.
  1877. */
  1878. virtual bool Merge(wxRichTextObject* WXUNUSED(object), wxRichTextDrawingContext& WXUNUSED(context)) { return false; }
  1879. /**
  1880. JACS
  1881. Returns @true if this object can potentially be split, by virtue of having
  1882. different virtual attributes for individual sub-objects.
  1883. */
  1884. virtual bool CanSplit(wxRichTextDrawingContext& WXUNUSED(context)) const { return false; }
  1885. /**
  1886. Returns the final object in the split objects if this object was split due to differences between sub-object virtual attributes.
  1887. Returns itself if it was not split.
  1888. */
  1889. virtual wxRichTextObject* Split(wxRichTextDrawingContext& WXUNUSED(context)) { return this; }
  1890. /**
  1891. Dump object data to the given output stream for debugging.
  1892. */
  1893. virtual void Dump(wxTextOutputStream& stream);
  1894. /**
  1895. Returns @true if we can edit the object's properties via a GUI.
  1896. */
  1897. virtual bool CanEditProperties() const { return false; }
  1898. /**
  1899. Edits the object's properties via a GUI.
  1900. */
  1901. virtual bool EditProperties(wxWindow* WXUNUSED(parent), wxRichTextBuffer* WXUNUSED(buffer)) { return false; }
  1902. /**
  1903. Returns the label to be used for the properties context menu item.
  1904. */
  1905. virtual wxString GetPropertiesMenuLabel() const { return wxEmptyString; }
  1906. /**
  1907. Returns @true if objects of this class can accept the focus, i.e. a call to SetFocusObject
  1908. is possible. For example, containers supporting text, such as a text box object, can accept the focus,
  1909. but a table can't (set the focus to individual cells instead).
  1910. */
  1911. virtual bool AcceptsFocus() const { return false; }
  1912. #if wxUSE_XML
  1913. /**
  1914. Imports this object from XML.
  1915. */
  1916. virtual bool ImportFromXML(wxRichTextBuffer* buffer, wxXmlNode* node, wxRichTextXMLHandler* handler, bool* recurse);
  1917. #endif
  1918. #if wxRICHTEXT_HAVE_DIRECT_OUTPUT
  1919. /**
  1920. Exports this object directly to the given stream, bypassing the creation of a wxXmlNode hierarchy.
  1921. This method is considerably faster than creating a tree first. However, both versions of ExportXML must be
  1922. implemented so that if the tree method is made efficient in the future, we can deprecate the
  1923. more verbose direct output method. Compiled only if wxRICHTEXT_HAVE_DIRECT_OUTPUT is defined (on by default).
  1924. */
  1925. virtual bool ExportXML(wxOutputStream& stream, int indent, wxRichTextXMLHandler* handler);
  1926. #endif
  1927. #if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT
  1928. /**
  1929. Exports this object to the given parent node, usually creating at least one child node.
  1930. This method is less efficient than the direct-to-stream method but is retained to allow for
  1931. switching to this method if we make it more efficient. Compiled only if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT is defined
  1932. (on by default).
  1933. */
  1934. virtual bool ExportXML(wxXmlNode* parent, wxRichTextXMLHandler* handler);
  1935. #endif
  1936. /**
  1937. Returns @true if this object takes note of paragraph attributes (text and image objects don't).
  1938. */
  1939. virtual bool UsesParagraphAttributes() const { return true; }
  1940. /**
  1941. Returns the XML node name of this object. This must be overridden for wxXmlNode-base XML export to work.
  1942. */
  1943. virtual wxString GetXMLNodeName() const { return wxT("unknown"); }
  1944. /**
  1945. Invalidates the object at the given range. With no argument, invalidates the whole object.
  1946. */
  1947. virtual void Invalidate(const wxRichTextRange& invalidRange = wxRICHTEXT_ALL);
  1948. /**
  1949. Returns @true if this object can handle the selections of its children, fOr example a table.
  1950. Required for composite selection handling to work.
  1951. */
  1952. virtual bool HandlesChildSelections() const { return false; }
  1953. /**
  1954. Returns a selection object specifying the selections between start and end character positions.
  1955. For example, a table would deduce what cells (of range length 1) are selected when dragging across the table.
  1956. */
  1957. virtual wxRichTextSelection GetSelection(long WXUNUSED(start), long WXUNUSED(end)) const { return wxRichTextSelection(); }
  1958. // Accessors
  1959. /**
  1960. Gets the cached object size as calculated by Layout.
  1961. */
  1962. virtual wxSize GetCachedSize() const { return m_size; }
  1963. /**
  1964. Sets the cached object size as calculated by Layout.
  1965. */
  1966. virtual void SetCachedSize(const wxSize& sz) { m_size = sz; }
  1967. /**
  1968. Gets the maximum object size as calculated by Layout. This allows
  1969. us to fit an object to its contents or allocate extra space if required.
  1970. */
  1971. virtual wxSize GetMaxSize() const { return m_maxSize; }
  1972. /**
  1973. Sets the maximum object size as calculated by Layout. This allows
  1974. us to fit an object to its contents or allocate extra space if required.
  1975. */
  1976. virtual void SetMaxSize(const wxSize& sz) { m_maxSize = sz; }
  1977. /**
  1978. Gets the minimum object size as calculated by Layout. This allows
  1979. us to constrain an object to its absolute minimum size if necessary.
  1980. */
  1981. virtual wxSize GetMinSize() const { return m_minSize; }
  1982. /**
  1983. Sets the minimum object size as calculated by Layout. This allows
  1984. us to constrain an object to its absolute minimum size if necessary.
  1985. */
  1986. virtual void SetMinSize(const wxSize& sz) { m_minSize = sz; }
  1987. /**
  1988. Gets the 'natural' size for an object. For an image, it would be the
  1989. image size.
  1990. */
  1991. virtual wxTextAttrSize GetNaturalSize() const { return wxTextAttrSize(); }
  1992. /**
  1993. Returns the object position in pixels.
  1994. */
  1995. virtual wxPoint GetPosition() const { return m_pos; }
  1996. /**
  1997. Sets the object position in pixels.
  1998. */
  1999. virtual void SetPosition(const wxPoint& pos) { m_pos = pos; }
  2000. /**
  2001. Returns the absolute object position, by traversing up the child/parent hierarchy.
  2002. TODO: may not be needed, if all object positions are in fact relative to the
  2003. top of the coordinate space.
  2004. */
  2005. virtual wxPoint GetAbsolutePosition() const;
  2006. /**
  2007. Returns the rectangle enclosing the object.
  2008. */
  2009. virtual wxRect GetRect() const { return wxRect(GetPosition(), GetCachedSize()); }
  2010. /**
  2011. Sets the object's range within its container.
  2012. */
  2013. void SetRange(const wxRichTextRange& range) { m_range = range; }
  2014. /**
  2015. Returns the object's range.
  2016. */
  2017. const wxRichTextRange& GetRange() const { return m_range; }
  2018. /**
  2019. Returns the object's range.
  2020. */
  2021. wxRichTextRange& GetRange() { return m_range; }
  2022. /**
  2023. Set the object's own range, for a top-level object with its own position space.
  2024. */
  2025. void SetOwnRange(const wxRichTextRange& range) { m_ownRange = range; }
  2026. /**
  2027. Returns the object's own range (valid if top-level).
  2028. */
  2029. const wxRichTextRange& GetOwnRange() const { return m_ownRange; }
  2030. /**
  2031. Returns the object's own range (valid if top-level).
  2032. */
  2033. wxRichTextRange& GetOwnRange() { return m_ownRange; }
  2034. /**
  2035. Returns the object's own range only if a top-level object.
  2036. */
  2037. wxRichTextRange GetOwnRangeIfTopLevel() const { return IsTopLevel() ? m_ownRange : m_range; }
  2038. /**
  2039. Returns @true if this object is composite.
  2040. */
  2041. virtual bool IsComposite() const { return false; }
  2042. /**
  2043. Returns @true if no user editing can be done inside the object. This returns @true for simple objects,
  2044. @false for most composite objects, but @true for fields, which if composite, should not be user-edited.
  2045. */
  2046. virtual bool IsAtomic() const { return true; }
  2047. /**
  2048. Returns a pointer to the parent object.
  2049. */
  2050. virtual wxRichTextObject* GetParent() const { return m_parent; }
  2051. /**
  2052. Sets the pointer to the parent object.
  2053. */
  2054. virtual void SetParent(wxRichTextObject* parent) { m_parent = parent; }
  2055. /**
  2056. Returns the top-level container of this object.
  2057. May return itself if it's a container; use GetParentContainer to return
  2058. a different container.
  2059. */
  2060. virtual wxRichTextParagraphLayoutBox* GetContainer() const;
  2061. /**
  2062. Returns the top-level container of this object.
  2063. Returns a different container than itself, unless there's no parent, in which case it will return NULL.
  2064. */
  2065. virtual wxRichTextParagraphLayoutBox* GetParentContainer() const { return GetParent() ? GetParent()->GetContainer() : GetContainer(); }
  2066. /**
  2067. Set the margin around the object, in pixels.
  2068. */
  2069. virtual void SetMargins(int margin);
  2070. /**
  2071. Set the margin around the object, in pixels.
  2072. */
  2073. virtual void SetMargins(int leftMargin, int rightMargin, int topMargin, int bottomMargin);
  2074. /**
  2075. Returns the left margin of the object, in pixels.
  2076. */
  2077. virtual int GetLeftMargin() const;
  2078. /**
  2079. Returns the right margin of the object, in pixels.
  2080. */
  2081. virtual int GetRightMargin() const;
  2082. /**
  2083. Returns the top margin of the object, in pixels.
  2084. */
  2085. virtual int GetTopMargin() const;
  2086. /**
  2087. Returns the bottom margin of the object, in pixels.
  2088. */
  2089. virtual int GetBottomMargin() const;
  2090. /**
  2091. Calculates the available content space in the given rectangle, given the
  2092. margins, border and padding specified in the object's attributes.
  2093. */
  2094. virtual wxRect GetAvailableContentArea(wxDC& dc, wxRichTextDrawingContext& context, const wxRect& outerRect) const;
  2095. /**
  2096. Lays out the object first with a given amount of space, and then if no width was specified in attr,
  2097. lays out the object again using the minimum size. @a availableParentSpace is the maximum space
  2098. for the object, whereas @a availableContainerSpace is the container with which relative positions and
  2099. sizes should be computed. For example, a text box whose space has already been constrained
  2100. in a previous layout pass to @a availableParentSpace, but should have a width of 50% of @a availableContainerSpace.
  2101. (If these two rects were the same, a 2nd pass could see the object getting too small.)
  2102. */
  2103. virtual bool LayoutToBestSize(wxDC& dc, wxRichTextDrawingContext& context, wxRichTextBuffer* buffer,
  2104. const wxRichTextAttr& parentAttr, const wxRichTextAttr& attr,
  2105. const wxRect& availableParentSpace, const wxRect& availableContainerSpace, int style);
  2106. /**
  2107. Adjusts the attributes for virtual attribute provision, collapsed borders, etc.
  2108. */
  2109. virtual bool AdjustAttributes(wxRichTextAttr& attr, wxRichTextDrawingContext& context);
  2110. /**
  2111. Sets the object's attributes.
  2112. */
  2113. void SetAttributes(const wxRichTextAttr& attr) { m_attributes = attr; }
  2114. /**
  2115. Returns the object's attributes.
  2116. */
  2117. const wxRichTextAttr& GetAttributes() const { return m_attributes; }
  2118. /**
  2119. Returns the object's attributes.
  2120. */
  2121. wxRichTextAttr& GetAttributes() { return m_attributes; }
  2122. /**
  2123. Returns the object's properties.
  2124. */
  2125. wxRichTextProperties& GetProperties() { return m_properties; }
  2126. /**
  2127. Returns the object's properties.
  2128. */
  2129. const wxRichTextProperties& GetProperties() const { return m_properties; }
  2130. /**
  2131. Sets the object's properties.
  2132. */
  2133. void SetProperties(const wxRichTextProperties& props) { m_properties = props; }
  2134. /**
  2135. Sets the stored descent value.
  2136. */
  2137. void SetDescent(int descent) { m_descent = descent; }
  2138. /**
  2139. Returns the stored descent value.
  2140. */
  2141. int GetDescent() const { return m_descent; }
  2142. /**
  2143. Returns the containing buffer.
  2144. */
  2145. wxRichTextBuffer* GetBuffer() const;
  2146. /**
  2147. Sets the identifying name for this object as a property using the "name" key.
  2148. */
  2149. void SetName(const wxString& name) { m_properties.SetProperty(wxT("name"), name); }
  2150. /**
  2151. Returns the identifying name for this object from the properties, using the "name" key.
  2152. */
  2153. wxString GetName() const { return m_properties.GetPropertyString(wxT("name")); }
  2154. /**
  2155. Returns @true if this object is top-level, i.e. contains its own paragraphs, such as a text box.
  2156. */
  2157. virtual bool IsTopLevel() const { return false; }
  2158. /**
  2159. Returns @true if the object will be shown, @false otherwise.
  2160. */
  2161. bool IsShown() const { return m_show; }
  2162. // Operations
  2163. /**
  2164. Call to show or hide this object. This function does not cause the content to be
  2165. laid out or redrawn.
  2166. */
  2167. virtual void Show(bool show) { m_show = show; }
  2168. /**
  2169. Clones the object.
  2170. */
  2171. virtual wxRichTextObject* Clone() const { return NULL; }
  2172. /**
  2173. Copies the object.
  2174. */
  2175. void Copy(const wxRichTextObject& obj);
  2176. /**
  2177. Reference-counting allows us to use the same object in multiple
  2178. lists (not yet used).
  2179. */
  2180. void Reference() { m_refCount ++; }
  2181. /**
  2182. Reference-counting allows us to use the same object in multiple
  2183. lists (not yet used).
  2184. */
  2185. void Dereference();
  2186. /**
  2187. Moves the object recursively, by adding the offset from old to new.
  2188. */
  2189. virtual void Move(const wxPoint& pt);
  2190. /**
  2191. Converts units in tenths of a millimetre to device units.
  2192. */
  2193. int ConvertTenthsMMToPixels(wxDC& dc, int units) const;
  2194. /**
  2195. Converts units in tenths of a millimetre to device units.
  2196. */
  2197. static int ConvertTenthsMMToPixels(int ppi, int units, double scale = 1.0);
  2198. /**
  2199. Convert units in pixels to tenths of a millimetre.
  2200. */
  2201. int ConvertPixelsToTenthsMM(wxDC& dc, int pixels) const;
  2202. /**
  2203. Convert units in pixels to tenths of a millimetre.
  2204. */
  2205. static int ConvertPixelsToTenthsMM(int ppi, int pixels, double scale = 1.0);
  2206. /**
  2207. Draws the borders and background for the given rectangle and attributes.
  2208. @a boxRect is taken to be the outer margin box, not the box around the content.
  2209. */
  2210. static bool DrawBoxAttributes(wxDC& dc, wxRichTextBuffer* buffer, const wxRichTextAttr& attr, const wxRect& boxRect, int flags = 0, wxRichTextObject* obj = NULL);
  2211. /**
  2212. Draws a border.
  2213. */
  2214. static bool DrawBorder(wxDC& dc, wxRichTextBuffer* buffer, const wxTextAttrBorders& attr, const wxRect& rect, int flags = 0);
  2215. /**
  2216. Returns the various rectangles of the box model in pixels. You can either specify @a contentRect (inner)
  2217. or @a marginRect (outer), and the other must be the default rectangle (no width or height).
  2218. Note that the outline doesn't affect the position of the rectangle, it's drawn in whatever space
  2219. is available.
  2220. */
  2221. static bool GetBoxRects(wxDC& dc, wxRichTextBuffer* buffer, const wxRichTextAttr& attr, wxRect& marginRect, wxRect& borderRect, wxRect& contentRect, wxRect& paddingRect, wxRect& outlineRect);
  2222. /**
  2223. Returns the total margin for the object in pixels, taking into account margin, padding and border size.
  2224. */
  2225. static bool GetTotalMargin(wxDC& dc, wxRichTextBuffer* buffer, const wxRichTextAttr& attr, int& leftMargin, int& rightMargin,
  2226. int& topMargin, int& bottomMargin);
  2227. /**
  2228. Returns the rectangle which the child has available to it given restrictions specified in the
  2229. child attribute, e.g. 50% width of the parent, 400 pixels, x position 20% of the parent, etc.
  2230. availableContainerSpace might be a parent that the cell has to compute its width relative to.
  2231. E.g. a cell that's 50% of its parent.
  2232. */
  2233. static wxRect AdjustAvailableSpace(wxDC& dc, wxRichTextBuffer* buffer, const wxRichTextAttr& parentAttr, const wxRichTextAttr& childAttr,
  2234. const wxRect& availableParentSpace, const wxRect& availableContainerSpace);
  2235. protected:
  2236. wxSize m_size;
  2237. wxSize m_maxSize;
  2238. wxSize m_minSize;
  2239. wxPoint m_pos;
  2240. int m_descent; // Descent for this object (if any)
  2241. int m_refCount;
  2242. bool m_show;
  2243. wxRichTextObject* m_parent;
  2244. // The range of this object (start position to end position)
  2245. wxRichTextRange m_range;
  2246. // The internal range of this object, if it's a top-level object with its own range space
  2247. wxRichTextRange m_ownRange;
  2248. // Attributes
  2249. wxRichTextAttr m_attributes;
  2250. // Properties
  2251. wxRichTextProperties m_properties;
  2252. };
  2253. WX_DECLARE_LIST_WITH_DECL( wxRichTextObject, wxRichTextObjectList, class WXDLLIMPEXP_RICHTEXT );
  2254. /**
  2255. @class wxRichTextCompositeObject
  2256. Objects of this class can contain other objects.
  2257. @library{wxrichtext}
  2258. @category{richtext}
  2259. @see wxRichTextObject, wxRichTextBuffer, wxRichTextCtrl
  2260. */
  2261. class WXDLLIMPEXP_RICHTEXT wxRichTextCompositeObject: public wxRichTextObject
  2262. {
  2263. DECLARE_CLASS(wxRichTextCompositeObject)
  2264. public:
  2265. // Constructors
  2266. wxRichTextCompositeObject(wxRichTextObject* parent = NULL);
  2267. virtual ~wxRichTextCompositeObject();
  2268. // Overridables
  2269. virtual int HitTest(wxDC& dc, wxRichTextDrawingContext& context, const wxPoint& pt, long& textPosition, wxRichTextObject** obj, wxRichTextObject** contextObj, int flags = 0);
  2270. virtual bool FindPosition(wxDC& dc, wxRichTextDrawingContext& context, long index, wxPoint& pt, int* height, bool forceLineStart);
  2271. virtual void CalculateRange(long start, long& end);
  2272. virtual bool DeleteRange(const wxRichTextRange& range);
  2273. virtual wxString GetTextForRange(const wxRichTextRange& range) const;
  2274. virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, wxRichTextDrawingContext& context, int flags, const wxPoint& position = wxPoint(0,0), const wxSize& parentSize = wxDefaultSize, wxArrayInt* partialExtents = NULL) const;
  2275. virtual void Dump(wxTextOutputStream& stream);
  2276. virtual void Invalidate(const wxRichTextRange& invalidRange = wxRICHTEXT_ALL);
  2277. // Accessors
  2278. /**
  2279. Returns the children.
  2280. */
  2281. wxRichTextObjectList& GetChildren() { return m_children; }
  2282. /**
  2283. Returns the children.
  2284. */
  2285. const wxRichTextObjectList& GetChildren() const { return m_children; }
  2286. /**
  2287. Returns the number of children.
  2288. */
  2289. size_t GetChildCount() const ;
  2290. /**
  2291. Returns the nth child.
  2292. */
  2293. wxRichTextObject* GetChild(size_t n) const ;
  2294. /**
  2295. Returns @true if this object is composite.
  2296. */
  2297. virtual bool IsComposite() const { return true; }
  2298. /**
  2299. Returns @true if no user editing can be done inside the object. This returns @true for simple objects,
  2300. @false for most composite objects, but @true for fields, which if composite, should not be user-edited.
  2301. */
  2302. virtual bool IsAtomic() const { return false; }
  2303. /**
  2304. Returns true if the buffer is empty.
  2305. */
  2306. virtual bool IsEmpty() const { return GetChildCount() == 0; }
  2307. /**
  2308. Returns the child object at the given character position.
  2309. */
  2310. virtual wxRichTextObject* GetChildAtPosition(long pos) const;
  2311. // Operations
  2312. void Copy(const wxRichTextCompositeObject& obj);
  2313. void operator= (const wxRichTextCompositeObject& obj) { Copy(obj); }
  2314. /**
  2315. Appends a child, returning the position.
  2316. */
  2317. size_t AppendChild(wxRichTextObject* child) ;
  2318. /**
  2319. Inserts the child in front of the given object, or at the beginning.
  2320. */
  2321. bool InsertChild(wxRichTextObject* child, wxRichTextObject* inFrontOf) ;
  2322. /**
  2323. Removes and optionally deletes the specified child.
  2324. */
  2325. bool RemoveChild(wxRichTextObject* child, bool deleteChild = false) ;
  2326. /**
  2327. Deletes all the children.
  2328. */
  2329. bool DeleteChildren() ;
  2330. /**
  2331. Recursively merges all pieces that can be merged.
  2332. */
  2333. bool Defragment(wxRichTextDrawingContext& context, const wxRichTextRange& range = wxRICHTEXT_ALL);
  2334. /**
  2335. Moves the object recursively, by adding the offset from old to new.
  2336. */
  2337. virtual void Move(const wxPoint& pt);
  2338. protected:
  2339. wxRichTextObjectList m_children;
  2340. };
  2341. /**
  2342. @class wxRichTextParagraphLayoutBox
  2343. This class knows how to lay out paragraphs.
  2344. @library{wxrichtext}
  2345. @category{richtext}
  2346. @see wxRichTextCompositeObject, wxRichTextObject, wxRichTextBuffer, wxRichTextCtrl
  2347. */
  2348. class WXDLLIMPEXP_RICHTEXT wxRichTextParagraphLayoutBox: public wxRichTextCompositeObject
  2349. {
  2350. DECLARE_DYNAMIC_CLASS(wxRichTextParagraphLayoutBox)
  2351. public:
  2352. // Constructors
  2353. wxRichTextParagraphLayoutBox(wxRichTextObject* parent = NULL);
  2354. wxRichTextParagraphLayoutBox(const wxRichTextParagraphLayoutBox& obj): wxRichTextCompositeObject() { Init(); Copy(obj); }
  2355. ~wxRichTextParagraphLayoutBox();
  2356. // Overridables
  2357. virtual int HitTest(wxDC& dc, wxRichTextDrawingContext& context, const wxPoint& pt, long& textPosition, wxRichTextObject** obj, wxRichTextObject** contextObj, int flags = 0);
  2358. virtual bool Draw(wxDC& dc, wxRichTextDrawingContext& context, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style);
  2359. virtual bool Layout(wxDC& dc, wxRichTextDrawingContext& context, const wxRect& rect, const wxRect& parentRect, int style);
  2360. virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, wxRichTextDrawingContext& context, int flags, const wxPoint& position = wxPoint(0,0), const wxSize& parentSize = wxDefaultSize, wxArrayInt* partialExtents = NULL) const;
  2361. virtual bool DeleteRange(const wxRichTextRange& range);
  2362. virtual wxString GetTextForRange(const wxRichTextRange& range) const;
  2363. #if wxUSE_XML
  2364. virtual bool ImportFromXML(wxRichTextBuffer* buffer, wxXmlNode* node, wxRichTextXMLHandler* handler, bool* recurse);
  2365. #endif
  2366. #if wxRICHTEXT_HAVE_DIRECT_OUTPUT
  2367. virtual bool ExportXML(wxOutputStream& stream, int indent, wxRichTextXMLHandler* handler);
  2368. #endif
  2369. #if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT
  2370. virtual bool ExportXML(wxXmlNode* parent, wxRichTextXMLHandler* handler);
  2371. #endif
  2372. virtual wxString GetXMLNodeName() const { return wxT("paragraphlayout"); }
  2373. virtual bool AcceptsFocus() const { return true; }
  2374. // Accessors
  2375. /**
  2376. Associates a control with the buffer, for operations that for example require refreshing the window.
  2377. */
  2378. void SetRichTextCtrl(wxRichTextCtrl* ctrl) { m_ctrl = ctrl; }
  2379. /**
  2380. Returns the associated control.
  2381. */
  2382. wxRichTextCtrl* GetRichTextCtrl() const { return m_ctrl; }
  2383. /**
  2384. Sets a flag indicating whether the last paragraph is partial or complete.
  2385. */
  2386. void SetPartialParagraph(bool partialPara) { m_partialParagraph = partialPara; }
  2387. /**
  2388. Returns a flag indicating whether the last paragraph is partial or complete.
  2389. */
  2390. bool GetPartialParagraph() const { return m_partialParagraph; }
  2391. /**
  2392. Returns the style sheet associated with the overall buffer.
  2393. */
  2394. virtual wxRichTextStyleSheet* GetStyleSheet() const;
  2395. virtual bool IsTopLevel() const { return true; }
  2396. // Operations
  2397. /**
  2398. Submits a command to insert paragraphs.
  2399. */
  2400. bool InsertParagraphsWithUndo(wxRichTextBuffer* buffer, long pos, const wxRichTextParagraphLayoutBox& paragraphs, wxRichTextCtrl* ctrl, int flags = 0);
  2401. /**
  2402. Submits a command to insert the given text.
  2403. */
  2404. bool InsertTextWithUndo(wxRichTextBuffer* buffer, long pos, const wxString& text, wxRichTextCtrl* ctrl, int flags = 0);
  2405. /**
  2406. Submits a command to insert the given text.
  2407. */
  2408. bool InsertNewlineWithUndo(wxRichTextBuffer* buffer, long pos, wxRichTextCtrl* ctrl, int flags = 0);
  2409. /**
  2410. Submits a command to insert the given image.
  2411. */
  2412. bool InsertImageWithUndo(wxRichTextBuffer* buffer, long pos, const wxRichTextImageBlock& imageBlock,
  2413. wxRichTextCtrl* ctrl, int flags, const wxRichTextAttr& textAttr);
  2414. /**
  2415. Submits a command to insert the given field. Field data can be included in properties.
  2416. @see wxRichTextField, wxRichTextFieldType, wxRichTextFieldTypeStandard
  2417. */
  2418. wxRichTextField* InsertFieldWithUndo(wxRichTextBuffer* buffer, long pos, const wxString& fieldType,
  2419. const wxRichTextProperties& properties,
  2420. wxRichTextCtrl* ctrl, int flags,
  2421. const wxRichTextAttr& textAttr);
  2422. /**
  2423. Returns the style that is appropriate for a new paragraph at this position.
  2424. If the previous paragraph has a paragraph style name, looks up the next-paragraph
  2425. style.
  2426. */
  2427. wxRichTextAttr GetStyleForNewParagraph(wxRichTextBuffer* buffer, long pos, bool caretPosition = false, bool lookUpNewParaStyle=false) const;
  2428. /**
  2429. Inserts an object.
  2430. */
  2431. wxRichTextObject* InsertObjectWithUndo(wxRichTextBuffer* buffer, long pos, wxRichTextObject *object, wxRichTextCtrl* ctrl, int flags = 0);
  2432. /**
  2433. Submits a command to delete this range.
  2434. */
  2435. bool DeleteRangeWithUndo(const wxRichTextRange& range, wxRichTextCtrl* ctrl, wxRichTextBuffer* buffer);
  2436. /**
  2437. Draws the floating objects in this buffer.
  2438. */
  2439. void DrawFloats(wxDC& dc, wxRichTextDrawingContext& context, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style);
  2440. /**
  2441. Moves an anchored object to another paragraph.
  2442. */
  2443. void MoveAnchoredObjectToParagraph(wxRichTextParagraph* from, wxRichTextParagraph* to, wxRichTextObject* obj);
  2444. /**
  2445. Initializes the object.
  2446. */
  2447. void Init();
  2448. /**
  2449. Clears all the children.
  2450. */
  2451. virtual void Clear();
  2452. /**
  2453. Clears and initializes with one blank paragraph.
  2454. */
  2455. virtual void Reset();
  2456. /**
  2457. Convenience function to add a paragraph of text.
  2458. */
  2459. virtual wxRichTextRange AddParagraph(const wxString& text, wxRichTextAttr* paraStyle = NULL);
  2460. /**
  2461. Convenience function to add an image.
  2462. */
  2463. virtual wxRichTextRange AddImage(const wxImage& image, wxRichTextAttr* paraStyle = NULL);
  2464. /**
  2465. Adds multiple paragraphs, based on newlines.
  2466. */
  2467. virtual wxRichTextRange AddParagraphs(const wxString& text, wxRichTextAttr* paraStyle = NULL);
  2468. /**
  2469. Returns the line at the given position. If @a caretPosition is true, the position is
  2470. a caret position, which is normally a smaller number.
  2471. */
  2472. virtual wxRichTextLine* GetLineAtPosition(long pos, bool caretPosition = false) const;
  2473. /**
  2474. Returns the line at the given y pixel position, or the last line.
  2475. */
  2476. virtual wxRichTextLine* GetLineAtYPosition(int y) const;
  2477. /**
  2478. Returns the paragraph at the given character or caret position.
  2479. */
  2480. virtual wxRichTextParagraph* GetParagraphAtPosition(long pos, bool caretPosition = false) const;
  2481. /**
  2482. Returns the line size at the given position.
  2483. */
  2484. virtual wxSize GetLineSizeAtPosition(long pos, bool caretPosition = false) const;
  2485. /**
  2486. Given a position, returns the number of the visible line (potentially many to a paragraph),
  2487. starting from zero at the start of the buffer. We also have to pass a bool (@a startOfLine)
  2488. that indicates whether the caret is being shown at the end of the previous line or at the start
  2489. of the next, since the caret can be shown at two visible positions for the same underlying
  2490. position.
  2491. */
  2492. virtual long GetVisibleLineNumber(long pos, bool caretPosition = false, bool startOfLine = false) const;
  2493. /**
  2494. Given a line number, returns the corresponding wxRichTextLine object.
  2495. */
  2496. virtual wxRichTextLine* GetLineForVisibleLineNumber(long lineNumber) const;
  2497. /**
  2498. Returns the leaf object in a paragraph at this position.
  2499. */
  2500. virtual wxRichTextObject* GetLeafObjectAtPosition(long position) const;
  2501. /**
  2502. Returns the paragraph by number.
  2503. */
  2504. virtual wxRichTextParagraph* GetParagraphAtLine(long paragraphNumber) const;
  2505. /**
  2506. Returns the paragraph for a given line.
  2507. */
  2508. virtual wxRichTextParagraph* GetParagraphForLine(wxRichTextLine* line) const;
  2509. /**
  2510. Returns the length of the paragraph.
  2511. */
  2512. virtual int GetParagraphLength(long paragraphNumber) const;
  2513. /**
  2514. Returns the number of paragraphs.
  2515. */
  2516. virtual int GetParagraphCount() const { return static_cast<int>(GetChildCount()); }
  2517. /**
  2518. Returns the number of visible lines.
  2519. */
  2520. virtual int GetLineCount() const;
  2521. /**
  2522. Returns the text of the paragraph.
  2523. */
  2524. virtual wxString GetParagraphText(long paragraphNumber) const;
  2525. /**
  2526. Converts zero-based line column and paragraph number to a position.
  2527. */
  2528. virtual long XYToPosition(long x, long y) const;
  2529. /**
  2530. Converts a zero-based position to line column and paragraph number.
  2531. */
  2532. virtual bool PositionToXY(long pos, long* x, long* y) const;
  2533. /**
  2534. Sets the attributes for the given range. Pass flags to determine how the
  2535. attributes are set.
  2536. The end point of range is specified as the last character position of the span
  2537. of text. So, for example, to set the style for a character at position 5,
  2538. use the range (5,5).
  2539. This differs from the wxRichTextCtrl API, where you would specify (5,6).
  2540. @a flags may contain a bit list of the following values:
  2541. - wxRICHTEXT_SETSTYLE_NONE: no style flag.
  2542. - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this operation should be
  2543. undoable.
  2544. - wxRICHTEXT_SETSTYLE_OPTIMIZE: specifies that the style should not be applied
  2545. if the combined style at this point is already the style in question.
  2546. - wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY: specifies that the style should only be
  2547. applied to paragraphs, and not the content.
  2548. This allows content styling to be preserved independently from that
  2549. of e.g. a named paragraph style.
  2550. - wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY: specifies that the style should only be
  2551. applied to characters, and not the paragraph.
  2552. This allows content styling to be preserved independently from that
  2553. of e.g. a named paragraph style.
  2554. - wxRICHTEXT_SETSTYLE_RESET: resets (clears) the existing style before applying
  2555. the new style.
  2556. - wxRICHTEXT_SETSTYLE_REMOVE: removes the specified style.
  2557. Only the style flags are used in this operation.
  2558. */
  2559. virtual bool SetStyle(const wxRichTextRange& range, const wxRichTextAttr& style, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO);
  2560. /**
  2561. Sets the attributes for the given object only, for example the box attributes for a text box.
  2562. */
  2563. virtual void SetStyle(wxRichTextObject *obj, const wxRichTextAttr& textAttr, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO);
  2564. /**
  2565. Returns the combined text attributes for this position.
  2566. This function gets the @e uncombined style - that is, the attributes associated
  2567. with the paragraph or character content, and not necessarily the combined
  2568. attributes you see on the screen. To get the combined attributes, use GetStyle().
  2569. If you specify (any) paragraph attribute in @e style's flags, this function
  2570. will fetch the paragraph attributes.
  2571. Otherwise, it will return the character attributes.
  2572. */
  2573. virtual bool GetStyle(long position, wxRichTextAttr& style);
  2574. /**
  2575. Returns the content (uncombined) attributes for this position.
  2576. */
  2577. virtual bool GetUncombinedStyle(long position, wxRichTextAttr& style);
  2578. /**
  2579. Implementation helper for GetStyle. If combineStyles is true, combine base, paragraph and
  2580. context attributes.
  2581. */
  2582. virtual bool DoGetStyle(long position, wxRichTextAttr& style, bool combineStyles = true);
  2583. /**
  2584. This function gets a style representing the common, combined attributes in the
  2585. given range.
  2586. Attributes which have different values within the specified range will not be
  2587. included the style flags.
  2588. The function is used to get the attributes to display in the formatting dialog:
  2589. the user can edit the attributes common to the selection, and optionally specify the
  2590. values of further attributes to be applied uniformly.
  2591. To apply the edited attributes, you can use SetStyle() specifying
  2592. the wxRICHTEXT_SETSTYLE_OPTIMIZE flag, which will only apply attributes that
  2593. are different from the @e combined attributes within the range.
  2594. So, the user edits the effective, displayed attributes for the range,
  2595. but his choice won't be applied unnecessarily to content. As an example,
  2596. say the style for a paragraph specifies bold, but the paragraph text doesn't
  2597. specify a weight.
  2598. The combined style is bold, and this is what the user will see on-screen and
  2599. in the formatting dialog. The user now specifies red text, in addition to bold.
  2600. When applying with SetStyle(), the content font weight attributes won't be
  2601. changed to bold because this is already specified by the paragraph.
  2602. However the text colour attributes @e will be changed to show red.
  2603. */
  2604. virtual bool GetStyleForRange(const wxRichTextRange& range, wxRichTextAttr& style);
  2605. /**
  2606. Combines @a style with @a currentStyle for the purpose of summarising the attributes of a range of
  2607. content.
  2608. */
  2609. bool CollectStyle(wxRichTextAttr& currentStyle, const wxRichTextAttr& style, wxRichTextAttr& clashingAttr, wxRichTextAttr& absentAttr);
  2610. //@{
  2611. /**
  2612. Sets the list attributes for the given range, passing flags to determine how
  2613. the attributes are set.
  2614. Either the style definition or the name of the style definition (in the current
  2615. sheet) can be passed.
  2616. @a flags is a bit list of the following:
  2617. - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable.
  2618. - wxRICHTEXT_SETSTYLE_RENUMBER: specifies that numbering should start from
  2619. @a startFrom, otherwise existing attributes are used.
  2620. - wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL: specifies that @a listLevel should be used
  2621. as the level for all paragraphs, otherwise the current indentation will be used.
  2622. @see NumberList(), PromoteList(), ClearListStyle().
  2623. */
  2624. virtual bool SetListStyle(const wxRichTextRange& range, wxRichTextListStyleDefinition* def, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1);
  2625. virtual bool SetListStyle(const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1);
  2626. //@}
  2627. /**
  2628. Clears the list style from the given range, clearing list-related attributes
  2629. and applying any named paragraph style associated with each paragraph.
  2630. @a flags is a bit list of the following:
  2631. - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable.
  2632. @see SetListStyle(), PromoteList(), NumberList()
  2633. */
  2634. virtual bool ClearListStyle(const wxRichTextRange& range, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO);
  2635. //@{
  2636. /**
  2637. Numbers the paragraphs in the given range.
  2638. Pass flags to determine how the attributes are set.
  2639. Either the style definition or the name of the style definition (in the current
  2640. sheet) can be passed.
  2641. @a flags is a bit list of the following:
  2642. - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable.
  2643. - wxRICHTEXT_SETSTYLE_RENUMBER: specifies that numbering should start from
  2644. @a startFrom, otherwise existing attributes are used.
  2645. - wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL: specifies that @a listLevel should be used
  2646. as the level for all paragraphs, otherwise the current indentation will be used.
  2647. @a def can be NULL to indicate that the existing list style should be used.
  2648. @see SetListStyle(), PromoteList(), ClearListStyle()
  2649. */
  2650. virtual bool NumberList(const wxRichTextRange& range, wxRichTextListStyleDefinition* def = NULL, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1);
  2651. virtual bool NumberList(const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1);
  2652. //@}
  2653. //@{
  2654. /**
  2655. Promotes the list items within the given range.
  2656. A positive @a promoteBy produces a smaller indent, and a negative number
  2657. produces a larger indent. Pass flags to determine how the attributes are set.
  2658. Either the style definition or the name of the style definition (in the current
  2659. sheet) can be passed.
  2660. @a flags is a bit list of the following:
  2661. - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable.
  2662. - wxRICHTEXT_SETSTYLE_RENUMBER: specifies that numbering should start from
  2663. @a startFrom, otherwise existing attributes are used.
  2664. - wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL: specifies that @a listLevel should be used
  2665. as the level for all paragraphs, otherwise the current indentation will be used.
  2666. @see SetListStyle(), SetListStyle(), ClearListStyle()
  2667. */
  2668. virtual bool PromoteList(int promoteBy, const wxRichTextRange& range, wxRichTextListStyleDefinition* def = NULL, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int specifiedLevel = -1);
  2669. virtual bool PromoteList(int promoteBy, const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int specifiedLevel = -1);
  2670. //@}
  2671. /**
  2672. Helper for NumberList and PromoteList, that does renumbering and promotion simultaneously
  2673. @a def can be NULL/empty to indicate that the existing list style should be used.
  2674. */
  2675. virtual bool DoNumberList(const wxRichTextRange& range, const wxRichTextRange& promotionRange, int promoteBy, wxRichTextListStyleDefinition* def, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1);
  2676. /**
  2677. Fills in the attributes for numbering a paragraph after previousParagraph.
  2678. */
  2679. virtual bool FindNextParagraphNumber(wxRichTextParagraph* previousParagraph, wxRichTextAttr& attr) const;
  2680. /**
  2681. Sets the properties for the given range, passing flags to determine how the
  2682. attributes are set. You can merge properties or replace them.
  2683. The end point of range is specified as the last character position of the span
  2684. of text, plus one. So, for example, to set the properties for a character at
  2685. position 5, use the range (5,6).
  2686. @a flags may contain a bit list of the following values:
  2687. - wxRICHTEXT_SETPROPERTIES_NONE: no flag.
  2688. - wxRICHTEXT_SETPROPERTIES_WITH_UNDO: specifies that this operation should be
  2689. undoable.
  2690. - wxRICHTEXT_SETPROPERTIES_PARAGRAPHS_ONLY: specifies that the properties should only be
  2691. applied to paragraphs, and not the content.
  2692. - wxRICHTEXT_SETPROPERTIES_CHARACTERS_ONLY: specifies that the properties should only be
  2693. applied to characters, and not the paragraph.
  2694. - wxRICHTEXT_SETPROPERTIES_RESET: resets (clears) the existing properties before applying
  2695. the new properties.
  2696. - wxRICHTEXT_SETPROPERTIES_REMOVE: removes the specified properties.
  2697. */
  2698. virtual bool SetProperties(const wxRichTextRange& range, const wxRichTextProperties& properties, int flags = wxRICHTEXT_SETPROPERTIES_WITH_UNDO);
  2699. /**
  2700. Sets with undo the properties for the given object.
  2701. */
  2702. virtual bool SetObjectPropertiesWithUndo(wxRichTextObject& obj, const wxRichTextProperties& properties, wxRichTextObject* objToSet = NULL);
  2703. /**
  2704. Test if this whole range has character attributes of the specified kind. If any
  2705. of the attributes are different within the range, the test fails. You
  2706. can use this to implement, for example, bold button updating. style must have
  2707. flags indicating which attributes are of interest.
  2708. */
  2709. virtual bool HasCharacterAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const;
  2710. /**
  2711. Test if this whole range has paragraph attributes of the specified kind. If any
  2712. of the attributes are different within the range, the test fails. You
  2713. can use this to implement, for example, centering button updating. style must have
  2714. flags indicating which attributes are of interest.
  2715. */
  2716. virtual bool HasParagraphAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const;
  2717. virtual wxRichTextObject* Clone() const { return new wxRichTextParagraphLayoutBox(*this); }
  2718. /**
  2719. Prepares the content just before insertion (or after buffer reset).
  2720. Currently is only called if undo mode is on.
  2721. */
  2722. virtual void PrepareContent(wxRichTextParagraphLayoutBox& container);
  2723. /**
  2724. Insert fragment into this box at the given position. If partialParagraph is true,
  2725. it is assumed that the last (or only) paragraph is just a piece of data with no paragraph
  2726. marker.
  2727. */
  2728. virtual bool InsertFragment(long position, wxRichTextParagraphLayoutBox& fragment);
  2729. /**
  2730. Make a copy of the fragment corresponding to the given range, putting it in @a fragment.
  2731. */
  2732. virtual bool CopyFragment(const wxRichTextRange& range, wxRichTextParagraphLayoutBox& fragment);
  2733. /**
  2734. Apply the style sheet to the buffer, for example if the styles have changed.
  2735. */
  2736. virtual bool ApplyStyleSheet(wxRichTextStyleSheet* styleSheet);
  2737. void Copy(const wxRichTextParagraphLayoutBox& obj);
  2738. void operator= (const wxRichTextParagraphLayoutBox& obj) { Copy(obj); }
  2739. /**
  2740. Calculate ranges.
  2741. */
  2742. virtual void UpdateRanges();
  2743. /**
  2744. Get all the text.
  2745. */
  2746. virtual wxString GetText() const;
  2747. /**
  2748. Sets the default style, affecting the style currently being applied
  2749. (for example, setting the default style to bold will cause subsequently
  2750. inserted text to be bold).
  2751. This is not cumulative - setting the default style will replace the previous
  2752. default style.
  2753. Setting it to a default attribute object makes new content take on the 'basic' style.
  2754. */
  2755. virtual bool SetDefaultStyle(const wxRichTextAttr& style);
  2756. /**
  2757. Returns the current default style, affecting the style currently being applied
  2758. (for example, setting the default style to bold will cause subsequently
  2759. inserted text to be bold).
  2760. */
  2761. virtual const wxRichTextAttr& GetDefaultStyle() const { return m_defaultAttributes; }
  2762. /**
  2763. Sets the basic (overall) style. This is the style of the whole
  2764. buffer before further styles are applied, unlike the default style, which
  2765. only affects the style currently being applied (for example, setting the default
  2766. style to bold will cause subsequently inserted text to be bold).
  2767. */
  2768. virtual void SetBasicStyle(const wxRichTextAttr& style) { m_attributes = style; }
  2769. /**
  2770. Returns the basic (overall) style.
  2771. This is the style of the whole buffer before further styles are applied,
  2772. unlike the default style, which only affects the style currently being
  2773. applied (for example, setting the default style to bold will cause
  2774. subsequently inserted text to be bold).
  2775. */
  2776. virtual const wxRichTextAttr& GetBasicStyle() const { return m_attributes; }
  2777. /**
  2778. Invalidates the buffer. With no argument, invalidates whole buffer.
  2779. */
  2780. virtual void Invalidate(const wxRichTextRange& invalidRange = wxRICHTEXT_ALL);
  2781. /**
  2782. Do the (in)validation for this object only.
  2783. */
  2784. virtual void DoInvalidate(const wxRichTextRange& invalidRange);
  2785. /**
  2786. Do the (in)validation both up and down the hierarchy.
  2787. */
  2788. virtual void InvalidateHierarchy(const wxRichTextRange& invalidRange = wxRICHTEXT_ALL);
  2789. /**
  2790. Gather information about floating objects. If untilObj is non-NULL,
  2791. will stop getting information if the current object is this, since we
  2792. will collect the rest later.
  2793. */
  2794. virtual bool UpdateFloatingObjects(const wxRect& availableRect, wxRichTextObject* untilObj = NULL);
  2795. /**
  2796. Get invalid range, rounding to entire paragraphs if argument is true.
  2797. */
  2798. wxRichTextRange GetInvalidRange(bool wholeParagraphs = false) const;
  2799. /**
  2800. Returns @true if this object needs layout.
  2801. */
  2802. bool IsDirty() const { return m_invalidRange != wxRICHTEXT_NONE; }
  2803. /**
  2804. Returns the wxRichTextFloatCollector of this object.
  2805. */
  2806. wxRichTextFloatCollector* GetFloatCollector() { return m_floatCollector; }
  2807. /**
  2808. Returns the number of floating objects at this level.
  2809. */
  2810. int GetFloatingObjectCount() const;
  2811. /**
  2812. Returns a list of floating objects.
  2813. */
  2814. bool GetFloatingObjects(wxRichTextObjectList& objects) const;
  2815. protected:
  2816. wxRichTextCtrl* m_ctrl;
  2817. wxRichTextAttr m_defaultAttributes;
  2818. // The invalidated range that will need full layout
  2819. wxRichTextRange m_invalidRange;
  2820. // Is the last paragraph partial or complete?
  2821. bool m_partialParagraph;
  2822. // The floating layout state
  2823. wxRichTextFloatCollector* m_floatCollector;
  2824. };
  2825. /**
  2826. @class wxRichTextBox
  2827. This class implements a floating or inline text box, containing paragraphs.
  2828. @library{wxrichtext}
  2829. @category{richtext}
  2830. @see wxRichTextParagraphLayoutBox, wxRichTextObject, wxRichTextBuffer, wxRichTextCtrl
  2831. */
  2832. class WXDLLIMPEXP_RICHTEXT wxRichTextBox: public wxRichTextParagraphLayoutBox
  2833. {
  2834. DECLARE_DYNAMIC_CLASS(wxRichTextBox)
  2835. public:
  2836. // Constructors
  2837. /**
  2838. Default constructor; optionally pass the parent object.
  2839. */
  2840. wxRichTextBox(wxRichTextObject* parent = NULL);
  2841. /**
  2842. Copy constructor.
  2843. */
  2844. wxRichTextBox(const wxRichTextBox& obj): wxRichTextParagraphLayoutBox() { Copy(obj); }
  2845. // Overridables
  2846. virtual bool Draw(wxDC& dc, wxRichTextDrawingContext& context, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style);
  2847. virtual wxString GetXMLNodeName() const { return wxT("textbox"); }
  2848. virtual bool CanEditProperties() const { return true; }
  2849. virtual bool EditProperties(wxWindow* parent, wxRichTextBuffer* buffer);
  2850. virtual wxString GetPropertiesMenuLabel() const { return wxGetTranslation("&Box"); }
  2851. // Accessors
  2852. // Operations
  2853. virtual wxRichTextObject* Clone() const { return new wxRichTextBox(*this); }
  2854. void Copy(const wxRichTextBox& obj);
  2855. protected:
  2856. };
  2857. /**
  2858. @class wxRichTextField
  2859. This class implements the general concept of a field, an object that represents
  2860. additional functionality such as a footnote, a bookmark, a page number, a table
  2861. of contents, and so on. Extra information (such as a bookmark name) can be stored
  2862. in the object properties.
  2863. Drawing, layout, and property editing is delegated to classes derived
  2864. from wxRichTextFieldType, such as instances of wxRichTextFieldTypeStandard; this makes
  2865. the use of fields an efficient method of introducing extra functionality, since
  2866. most of the information required to draw a field (such as a bitmap) is kept centrally
  2867. in a single field type definition.
  2868. The FieldType property, accessed by SetFieldType/GetFieldType, is used to retrieve
  2869. the field type definition. So be careful not to overwrite this property.
  2870. wxRichTextField is derived from wxRichTextParagraphLayoutBox, which means that it
  2871. can contain its own read-only content, refreshed when the application calls the UpdateField
  2872. function. Whether a field is treated as a composite or a single graphic is determined
  2873. by the field type definition. If using wxRichTextFieldTypeStandard, passing the display
  2874. type wxRICHTEXT_FIELD_STYLE_COMPOSITE to the field type definition causes the field
  2875. to behave like a composite; the other display styles display a simple graphic.
  2876. When implementing a composite field, you will still need to derive from wxRichTextFieldTypeStandard
  2877. or wxRichTextFieldType, if only to implement UpdateField to refresh the field content
  2878. appropriately. wxRichTextFieldTypeStandard is only one possible implementation, but
  2879. covers common needs especially for simple, static fields using text or a bitmap.
  2880. Register field types on application initialisation with the static function
  2881. wxRichTextBuffer::AddFieldType. They will be deleted automatically on
  2882. application exit.
  2883. An application can write a field to a control with wxRichTextCtrl::WriteField,
  2884. taking a field type, the properties for the field, and optional attributes.
  2885. @library{wxrichtext}
  2886. @category{richtext}
  2887. @see wxRichTextFieldTypeStandard, wxRichTextFieldType, wxRichTextParagraphLayoutBox, wxRichTextProperties, wxRichTextCtrl
  2888. */
  2889. class WXDLLIMPEXP_RICHTEXT wxRichTextField: public wxRichTextParagraphLayoutBox
  2890. {
  2891. DECLARE_DYNAMIC_CLASS(wxRichTextField)
  2892. public:
  2893. // Constructors
  2894. /**
  2895. Default constructor; optionally pass the parent object.
  2896. */
  2897. wxRichTextField(const wxString& fieldType = wxEmptyString, wxRichTextObject* parent = NULL);
  2898. /**
  2899. Copy constructor.
  2900. */
  2901. wxRichTextField(const wxRichTextField& obj): wxRichTextParagraphLayoutBox() { Copy(obj); }
  2902. // Overridables
  2903. virtual bool Draw(wxDC& dc, wxRichTextDrawingContext& context, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style);
  2904. virtual bool Layout(wxDC& dc, wxRichTextDrawingContext& context, const wxRect& rect, const wxRect& parentRect, int style);
  2905. virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, wxRichTextDrawingContext& context, int flags, const wxPoint& position = wxPoint(0,0), const wxSize& parentSize = wxDefaultSize, wxArrayInt* partialExtents = NULL) const;
  2906. virtual wxString GetXMLNodeName() const { return wxT("field"); }
  2907. virtual bool CanEditProperties() const;
  2908. virtual bool EditProperties(wxWindow* parent, wxRichTextBuffer* buffer);
  2909. virtual wxString GetPropertiesMenuLabel() const;
  2910. virtual bool AcceptsFocus() const { return false; }
  2911. virtual void CalculateRange(long start, long& end);
  2912. /**
  2913. If a field has children, we don't want the user to be able to edit it.
  2914. */
  2915. virtual bool IsAtomic() const { return true; }
  2916. virtual bool IsEmpty() const { return false; }
  2917. virtual bool IsTopLevel() const;
  2918. // Accessors
  2919. void SetFieldType(const wxString& fieldType) { GetProperties().SetProperty(wxT("FieldType"), fieldType); }
  2920. wxString GetFieldType() const { return GetProperties().GetPropertyString(wxT("FieldType")); }
  2921. // Operations
  2922. /**
  2923. Update the field; delegated to the associated field type. This would typically expand the field to its value,
  2924. if this is a dynamically changing and/or composite field.
  2925. */
  2926. virtual bool UpdateField(wxRichTextBuffer* buffer);
  2927. virtual wxRichTextObject* Clone() const { return new wxRichTextField(*this); }
  2928. void Copy(const wxRichTextField& obj);
  2929. protected:
  2930. };
  2931. /**
  2932. @class wxRichTextFieldType
  2933. The base class for custom field types. Each type definition handles one
  2934. field type. Override functions to provide drawing, layout, updating and
  2935. property editing functionality for a field.
  2936. Register field types on application initialisation with the static function
  2937. wxRichTextBuffer::AddFieldType. They will be deleted automatically on
  2938. application exit.
  2939. @library{wxrichtext}
  2940. @category{richtext}
  2941. @see wxRichTextFieldTypeStandard, wxRichTextField, wxRichTextCtrl
  2942. */
  2943. class WXDLLIMPEXP_RICHTEXT wxRichTextFieldType: public wxObject
  2944. {
  2945. DECLARE_CLASS(wxRichTextFieldType)
  2946. public:
  2947. /**
  2948. Creates a field type definition.
  2949. */
  2950. wxRichTextFieldType(const wxString& name = wxEmptyString)
  2951. : m_name(name)
  2952. { }
  2953. /**
  2954. Copy constructor.
  2955. */
  2956. wxRichTextFieldType(const wxRichTextFieldType& fieldType)
  2957. : wxObject(fieldType)
  2958. { Copy(fieldType); }
  2959. void Copy(const wxRichTextFieldType& fieldType) { m_name = fieldType.m_name; }
  2960. /**
  2961. Draw the item, within the given range. Some objects may ignore the range (for
  2962. example paragraphs) while others must obey it (lines, to implement wrapping)
  2963. */
  2964. virtual bool Draw(wxRichTextField* obj, wxDC& dc, wxRichTextDrawingContext& context, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style) = 0;
  2965. /**
  2966. Lay the item out at the specified position with the given size constraint.
  2967. Layout must set the cached size. @rect is the available space for the object,
  2968. and @a parentRect is the container that is used to determine a relative size
  2969. or position (for example if a text box must be 50% of the parent text box).
  2970. */
  2971. virtual bool Layout(wxRichTextField* obj, wxDC& dc, wxRichTextDrawingContext& context, const wxRect& rect, const wxRect& parentRect, int style) = 0;
  2972. /**
  2973. Returns the object size for the given range. Returns @false if the range
  2974. is invalid for this object.
  2975. */
  2976. virtual bool GetRangeSize(wxRichTextField* obj, const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, wxRichTextDrawingContext& context, int flags, const wxPoint& position = wxPoint(0,0), const wxSize& parentSize = wxDefaultSize, wxArrayInt* partialExtents = NULL) const = 0;
  2977. /**
  2978. Returns @true if we can edit the object's properties via a GUI.
  2979. */
  2980. virtual bool CanEditProperties(wxRichTextField* WXUNUSED(obj)) const { return false; }
  2981. /**
  2982. Edits the object's properties via a GUI.
  2983. */
  2984. virtual bool EditProperties(wxRichTextField* WXUNUSED(obj), wxWindow* WXUNUSED(parent), wxRichTextBuffer* WXUNUSED(buffer)) { return false; }
  2985. /**
  2986. Returns the label to be used for the properties context menu item.
  2987. */
  2988. virtual wxString GetPropertiesMenuLabel(wxRichTextField* WXUNUSED(obj)) const { return wxEmptyString; }
  2989. /**
  2990. Update the field. This would typically expand the field to its value,
  2991. if this is a dynamically changing and/or composite field.
  2992. */
  2993. virtual bool UpdateField(wxRichTextBuffer* WXUNUSED(buffer), wxRichTextField* WXUNUSED(obj)) { return false; }
  2994. /**
  2995. Returns @true if this object is top-level, i.e. contains its own paragraphs, such as a text box.
  2996. */
  2997. virtual bool IsTopLevel(wxRichTextField* WXUNUSED(obj)) const { return true; }
  2998. /**
  2999. Sets the field type name. There should be a unique name per field type object.
  3000. */
  3001. void SetName(const wxString& name) { m_name = name; }
  3002. /**
  3003. Returns the field type name. There should be a unique name per field type object.
  3004. */
  3005. wxString GetName() const { return m_name; }
  3006. protected:
  3007. wxString m_name;
  3008. };
  3009. WX_DECLARE_STRING_HASH_MAP(wxRichTextFieldType*, wxRichTextFieldTypeHashMap);
  3010. /**
  3011. @class wxRichTextFieldTypeStandard
  3012. A field type that can handle fields with text or bitmap labels, with a small range
  3013. of styles for implementing rectangular fields and fields that can be used for start
  3014. and end tags.
  3015. The border, text and background colours can be customised; the default is
  3016. white text on a black background.
  3017. The following display styles can be used.
  3018. @beginStyleTable
  3019. @style{wxRICHTEXT_FIELD_STYLE_COMPOSITE}
  3020. Creates a composite field; you will probably need to derive a new class to implement UpdateField.
  3021. @style{wxRICHTEXT_FIELD_STYLE_RECTANGLE}
  3022. Shows a rounded rectangle background.
  3023. @style{wxRICHTEXT_FIELD_STYLE_NO_BORDER}
  3024. Suppresses the background and border; mostly used with a bitmap label.
  3025. @style{wxRICHTEXT_FIELD_STYLE_START_TAG}
  3026. Shows a start tag background, with the pointy end facing right.
  3027. @style{wxRICHTEXT_FIELD_STYLE_END_TAG}
  3028. Shows an end tag background, with the pointy end facing left.
  3029. @endStyleTable
  3030. @library{wxrichtext}
  3031. @category{richtext}
  3032. @see wxRichTextFieldType, wxRichTextField, wxRichTextBuffer, wxRichTextCtrl
  3033. */
  3034. class WXDLLIMPEXP_RICHTEXT wxRichTextFieldTypeStandard: public wxRichTextFieldType
  3035. {
  3036. DECLARE_CLASS(wxRichTextFieldTypeStandard)
  3037. public:
  3038. // Display style types
  3039. enum { wxRICHTEXT_FIELD_STYLE_COMPOSITE = 0x01,
  3040. wxRICHTEXT_FIELD_STYLE_RECTANGLE = 0x02,
  3041. wxRICHTEXT_FIELD_STYLE_NO_BORDER = 0x04,
  3042. wxRICHTEXT_FIELD_STYLE_START_TAG = 0x08,
  3043. wxRICHTEXT_FIELD_STYLE_END_TAG = 0x10
  3044. };
  3045. /**
  3046. Constructor, creating a field type definition with a text label.
  3047. @param parent
  3048. The name of the type definition. This must be unique, and is the type
  3049. name used when adding a field to a control.
  3050. @param label
  3051. The text label to be shown on the field.
  3052. @param displayStyle
  3053. The display style: one of wxRICHTEXT_FIELD_STYLE_RECTANGLE,
  3054. wxRICHTEXT_FIELD_STYLE_NO_BORDER, wxRICHTEXT_FIELD_STYLE_START_TAG,
  3055. wxRICHTEXT_FIELD_STYLE_END_TAG.
  3056. */
  3057. wxRichTextFieldTypeStandard(const wxString& name, const wxString& label, int displayStyle = wxRICHTEXT_FIELD_STYLE_RECTANGLE);
  3058. /**
  3059. Constructor, creating a field type definition with a bitmap label.
  3060. @param parent
  3061. The name of the type definition. This must be unique, and is the type
  3062. name used when adding a field to a control.
  3063. @param label
  3064. The bitmap label to be shown on the field.
  3065. @param displayStyle
  3066. The display style: one of wxRICHTEXT_FIELD_STYLE_RECTANGLE,
  3067. wxRICHTEXT_FIELD_STYLE_NO_BORDER, wxRICHTEXT_FIELD_STYLE_START_TAG,
  3068. wxRICHTEXT_FIELD_STYLE_END_TAG.
  3069. */
  3070. wxRichTextFieldTypeStandard(const wxString& name, const wxBitmap& bitmap, int displayStyle = wxRICHTEXT_FIELD_STYLE_NO_BORDER);
  3071. /**
  3072. The default constructor.
  3073. */
  3074. wxRichTextFieldTypeStandard() { Init(); }
  3075. /**
  3076. The copy constructor.
  3077. */
  3078. wxRichTextFieldTypeStandard(const wxRichTextFieldTypeStandard& field)
  3079. : wxRichTextFieldType(field)
  3080. { Copy(field); }
  3081. /**
  3082. Initialises the object.
  3083. */
  3084. void Init();
  3085. /**
  3086. Copies the object.
  3087. */
  3088. void Copy(const wxRichTextFieldTypeStandard& field);
  3089. /**
  3090. The assignment operator.
  3091. */
  3092. void operator=(const wxRichTextFieldTypeStandard& field) { Copy(field); }
  3093. /**
  3094. Draw the item, within the given range. Some objects may ignore the range (for
  3095. example paragraphs) while others must obey it (lines, to implement wrapping)
  3096. */
  3097. virtual bool Draw(wxRichTextField* obj, wxDC& dc, wxRichTextDrawingContext& context, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style);
  3098. /**
  3099. Lay the item out at the specified position with the given size constraint.
  3100. Layout must set the cached size. @rect is the available space for the object,
  3101. and @a parentRect is the container that is used to determine a relative size
  3102. or position (for example if a text box must be 50% of the parent text box).
  3103. */
  3104. virtual bool Layout(wxRichTextField* obj, wxDC& dc, wxRichTextDrawingContext& context, const wxRect& rect, const wxRect& parentRect, int style);
  3105. /**
  3106. Returns the object size for the given range. Returns @false if the range
  3107. is invalid for this object.
  3108. */
  3109. virtual bool GetRangeSize(wxRichTextField* obj, const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, wxRichTextDrawingContext& context, int flags, const wxPoint& position = wxPoint(0,0), const wxSize& parentSize = wxDefaultSize, wxArrayInt* partialExtents = NULL) const;
  3110. /**
  3111. Get the size of the field, given the label, font size, and so on.
  3112. */
  3113. wxSize GetSize(wxRichTextField* obj, wxDC& dc, wxRichTextDrawingContext& context, int style) const;
  3114. /**
  3115. Returns @true if the display type is wxRICHTEXT_FIELD_STYLE_COMPOSITE, @false otherwise.
  3116. */
  3117. virtual bool IsTopLevel(wxRichTextField* WXUNUSED(obj)) const { return (GetDisplayStyle() & wxRICHTEXT_FIELD_STYLE_COMPOSITE) != 0; }
  3118. /**
  3119. Sets the text label for fields of this type.
  3120. */
  3121. void SetLabel(const wxString& label) { m_label = label; }
  3122. /**
  3123. Returns the text label for fields of this type.
  3124. */
  3125. const wxString& GetLabel() const { return m_label; }
  3126. /**
  3127. Sets the bitmap label for fields of this type.
  3128. */
  3129. void SetBitmap(const wxBitmap& bitmap) { m_bitmap = bitmap; }
  3130. /**
  3131. Gets the bitmap label for fields of this type.
  3132. */
  3133. const wxBitmap& GetBitmap() const { return m_bitmap; }
  3134. /**
  3135. Gets the display style for fields of this type.
  3136. */
  3137. int GetDisplayStyle() const { return m_displayStyle; }
  3138. /**
  3139. Sets the display style for fields of this type.
  3140. */
  3141. void SetDisplayStyle(int displayStyle) { m_displayStyle = displayStyle; }
  3142. /**
  3143. Gets the font used for drawing the text label.
  3144. */
  3145. const wxFont& GetFont() const { return m_font; }
  3146. /**
  3147. Sets the font used for drawing the text label.
  3148. */
  3149. void SetFont(const wxFont& font) { m_font = font; }
  3150. /**
  3151. Gets the colour used for drawing the text label.
  3152. */
  3153. const wxColour& GetTextColour() const { return m_textColour; }
  3154. /**
  3155. Sets the colour used for drawing the text label.
  3156. */
  3157. void SetTextColour(const wxColour& colour) { m_textColour = colour; }
  3158. /**
  3159. Gets the colour used for drawing the field border.
  3160. */
  3161. const wxColour& GetBorderColour() const { return m_borderColour; }
  3162. /**
  3163. Sets the colour used for drawing the field border.
  3164. */
  3165. void SetBorderColour(const wxColour& colour) { m_borderColour = colour; }
  3166. /**
  3167. Gets the colour used for drawing the field background.
  3168. */
  3169. const wxColour& GetBackgroundColour() const { return m_backgroundColour; }
  3170. /**
  3171. Sets the colour used for drawing the field background.
  3172. */
  3173. void SetBackgroundColour(const wxColour& colour) { m_backgroundColour = colour; }
  3174. /**
  3175. Sets the vertical padding (the distance between the border and the text).
  3176. */
  3177. void SetVerticalPadding(int padding) { m_verticalPadding = padding; }
  3178. /**
  3179. Gets the vertical padding (the distance between the border and the text).
  3180. */
  3181. int GetVerticalPadding() const { return m_verticalPadding; }
  3182. /**
  3183. Sets the horizontal padding (the distance between the border and the text).
  3184. */
  3185. void SetHorizontalPadding(int padding) { m_horizontalPadding = padding; }
  3186. /**
  3187. Sets the horizontal padding (the distance between the border and the text).
  3188. */
  3189. int GetHorizontalPadding() const { return m_horizontalPadding; }
  3190. /**
  3191. Sets the horizontal margin surrounding the field object.
  3192. */
  3193. void SetHorizontalMargin(int margin) { m_horizontalMargin = margin; }
  3194. /**
  3195. Gets the horizontal margin surrounding the field object.
  3196. */
  3197. int GetHorizontalMargin() const { return m_horizontalMargin; }
  3198. /**
  3199. Sets the vertical margin surrounding the field object.
  3200. */
  3201. void SetVerticalMargin(int margin) { m_verticalMargin = margin; }
  3202. /**
  3203. Gets the vertical margin surrounding the field object.
  3204. */
  3205. int GetVerticalMargin() const { return m_verticalMargin; }
  3206. protected:
  3207. wxString m_label;
  3208. int m_displayStyle;
  3209. wxFont m_font;
  3210. wxColour m_textColour;
  3211. wxColour m_borderColour;
  3212. wxColour m_backgroundColour;
  3213. int m_verticalPadding;
  3214. int m_horizontalPadding;
  3215. int m_horizontalMargin;
  3216. int m_verticalMargin;
  3217. wxBitmap m_bitmap;
  3218. };
  3219. /**
  3220. @class wxRichTextLine
  3221. This object represents a line in a paragraph, and stores
  3222. offsets from the start of the paragraph representing the
  3223. start and end positions of the line.
  3224. @library{wxrichtext}
  3225. @category{richtext}
  3226. @see wxRichTextBuffer, wxRichTextCtrl
  3227. */
  3228. class WXDLLIMPEXP_RICHTEXT wxRichTextLine
  3229. {
  3230. public:
  3231. // Constructors
  3232. wxRichTextLine(wxRichTextParagraph* parent);
  3233. wxRichTextLine(const wxRichTextLine& obj) { Init( NULL); Copy(obj); }
  3234. virtual ~wxRichTextLine() {}
  3235. // Overridables
  3236. // Accessors
  3237. /**
  3238. Sets the range associated with this line.
  3239. */
  3240. void SetRange(const wxRichTextRange& range) { m_range = range; }
  3241. /**
  3242. Sets the range associated with this line.
  3243. */
  3244. void SetRange(long from, long to) { m_range = wxRichTextRange(from, to); }
  3245. /**
  3246. Returns the parent paragraph.
  3247. */
  3248. wxRichTextParagraph* GetParent() { return m_parent; }
  3249. /**
  3250. Returns the range.
  3251. */
  3252. const wxRichTextRange& GetRange() const { return m_range; }
  3253. /**
  3254. Returns the range.
  3255. */
  3256. wxRichTextRange& GetRange() { return m_range; }
  3257. /**
  3258. Returns the absolute range.
  3259. */
  3260. wxRichTextRange GetAbsoluteRange() const;
  3261. /**
  3262. Returns the line size as calculated by Layout.
  3263. */
  3264. virtual wxSize GetSize() const { return m_size; }
  3265. /**
  3266. Sets the line size as calculated by Layout.
  3267. */
  3268. virtual void SetSize(const wxSize& sz) { m_size = sz; }
  3269. /**
  3270. Returns the object position relative to the parent.
  3271. */
  3272. virtual wxPoint GetPosition() const { return m_pos; }
  3273. /**
  3274. Sets the object position relative to the parent.
  3275. */
  3276. virtual void SetPosition(const wxPoint& pos) { m_pos = pos; }
  3277. /**
  3278. Returns the absolute object position.
  3279. */
  3280. virtual wxPoint GetAbsolutePosition() const;
  3281. /**
  3282. Returns the rectangle enclosing the line.
  3283. */
  3284. virtual wxRect GetRect() const { return wxRect(GetAbsolutePosition(), GetSize()); }
  3285. /**
  3286. Sets the stored descent.
  3287. */
  3288. void SetDescent(int descent) { m_descent = descent; }
  3289. /**
  3290. Returns the stored descent.
  3291. */
  3292. int GetDescent() const { return m_descent; }
  3293. #if wxRICHTEXT_USE_OPTIMIZED_LINE_DRAWING
  3294. wxArrayInt& GetObjectSizes() { return m_objectSizes; }
  3295. const wxArrayInt& GetObjectSizes() const { return m_objectSizes; }
  3296. #endif
  3297. // Operations
  3298. /**
  3299. Initialises the object.
  3300. */
  3301. void Init(wxRichTextParagraph* parent);
  3302. /**
  3303. Copies from @a obj.
  3304. */
  3305. void Copy(const wxRichTextLine& obj);
  3306. virtual wxRichTextLine* Clone() const { return new wxRichTextLine(*this); }
  3307. protected:
  3308. // The range of the line (start position to end position)
  3309. // This is relative to the parent paragraph.
  3310. wxRichTextRange m_range;
  3311. // Size and position measured relative to top of paragraph
  3312. wxPoint m_pos;
  3313. wxSize m_size;
  3314. // Maximum descent for this line (location of text baseline)
  3315. int m_descent;
  3316. // The parent object
  3317. wxRichTextParagraph* m_parent;
  3318. #if wxRICHTEXT_USE_OPTIMIZED_LINE_DRAWING
  3319. wxArrayInt m_objectSizes;
  3320. #endif
  3321. };
  3322. WX_DECLARE_LIST_WITH_DECL( wxRichTextLine, wxRichTextLineList , class WXDLLIMPEXP_RICHTEXT );
  3323. /**
  3324. @class wxRichTextParagraph
  3325. This object represents a single paragraph containing various objects such as text content, images, and further paragraph layout objects.
  3326. @library{wxrichtext}
  3327. @category{richtext}
  3328. @see wxRichTextBuffer, wxRichTextCtrl
  3329. */
  3330. class WXDLLIMPEXP_RICHTEXT wxRichTextParagraph: public wxRichTextCompositeObject
  3331. {
  3332. DECLARE_DYNAMIC_CLASS(wxRichTextParagraph)
  3333. public:
  3334. // Constructors
  3335. /**
  3336. Constructor taking a parent and style.
  3337. */
  3338. wxRichTextParagraph(wxRichTextObject* parent = NULL, wxRichTextAttr* style = NULL);
  3339. /**
  3340. Constructor taking a text string, a parent and paragraph and character attributes.
  3341. */
  3342. wxRichTextParagraph(const wxString& text, wxRichTextObject* parent = NULL, wxRichTextAttr* paraStyle = NULL, wxRichTextAttr* charStyle = NULL);
  3343. virtual ~wxRichTextParagraph();
  3344. wxRichTextParagraph(const wxRichTextParagraph& obj): wxRichTextCompositeObject() { Copy(obj); }
  3345. // Overridables
  3346. virtual bool Draw(wxDC& dc, wxRichTextDrawingContext& context, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style);
  3347. virtual bool Layout(wxDC& dc, wxRichTextDrawingContext& context, const wxRect& rect, const wxRect& parentRect, int style);
  3348. virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, wxRichTextDrawingContext& context, int flags, const wxPoint& position = wxPoint(0,0), const wxSize& parentSize = wxDefaultSize, wxArrayInt* partialExtents = NULL) const;
  3349. virtual bool FindPosition(wxDC& dc, wxRichTextDrawingContext& context, long index, wxPoint& pt, int* height, bool forceLineStart);
  3350. virtual int HitTest(wxDC& dc, wxRichTextDrawingContext& context, const wxPoint& pt, long& textPosition, wxRichTextObject** obj, wxRichTextObject** contextObj, int flags = 0);
  3351. virtual void CalculateRange(long start, long& end);
  3352. virtual wxString GetXMLNodeName() const { return wxT("paragraph"); }
  3353. // Accessors
  3354. /**
  3355. Returns the cached lines.
  3356. */
  3357. wxRichTextLineList& GetLines() { return m_cachedLines; }
  3358. // Operations
  3359. /**
  3360. Copies the object.
  3361. */
  3362. void Copy(const wxRichTextParagraph& obj);
  3363. virtual wxRichTextObject* Clone() const { return new wxRichTextParagraph(*this); }
  3364. /**
  3365. Clears the cached lines.
  3366. */
  3367. void ClearLines();
  3368. // Implementation
  3369. /**
  3370. Applies paragraph styles such as centering to the wrapped lines.
  3371. */
  3372. virtual void ApplyParagraphStyle(wxRichTextLine* line, const wxRichTextAttr& attr, const wxRect& rect, wxDC& dc);
  3373. /**
  3374. Inserts text at the given position.
  3375. */
  3376. virtual bool InsertText(long pos, const wxString& text);
  3377. /**
  3378. Splits an object at this position if necessary, and returns
  3379. the previous object, or NULL if inserting at the beginning.
  3380. */
  3381. virtual wxRichTextObject* SplitAt(long pos, wxRichTextObject** previousObject = NULL);
  3382. /**
  3383. Moves content to a list from this point.
  3384. */
  3385. virtual void MoveToList(wxRichTextObject* obj, wxList& list);
  3386. /**
  3387. Adds content back from a list.
  3388. */
  3389. virtual void MoveFromList(wxList& list);
  3390. /**
  3391. Returns the plain text searching from the start or end of the range.
  3392. The resulting string may be shorter than the range given.
  3393. */
  3394. bool GetContiguousPlainText(wxString& text, const wxRichTextRange& range, bool fromStart = true);
  3395. /**
  3396. Finds a suitable wrap position. @a wrapPosition is the last position in the line to the left
  3397. of the split.
  3398. */
  3399. bool FindWrapPosition(const wxRichTextRange& range, wxDC& dc, wxRichTextDrawingContext& context, int availableSpace, long& wrapPosition, wxArrayInt* partialExtents);
  3400. /**
  3401. Finds the object at the given position.
  3402. */
  3403. wxRichTextObject* FindObjectAtPosition(long position);
  3404. /**
  3405. Returns the bullet text for this paragraph.
  3406. */
  3407. wxString GetBulletText();
  3408. /**
  3409. Allocates or reuses a line object.
  3410. */
  3411. wxRichTextLine* AllocateLine(int pos);
  3412. /**
  3413. Clears remaining unused line objects, if any.
  3414. */
  3415. bool ClearUnusedLines(int lineCount);
  3416. /**
  3417. Returns combined attributes of the base style, paragraph style and character style. We use this to dynamically
  3418. retrieve the actual style.
  3419. */
  3420. wxRichTextAttr GetCombinedAttributes(const wxRichTextAttr& contentStyle, bool includingBoxAttr = false) const;
  3421. /**
  3422. Returns the combined attributes of the base style and paragraph style.
  3423. */
  3424. wxRichTextAttr GetCombinedAttributes(bool includingBoxAttr = false) const;
  3425. /**
  3426. Returns the first position from pos that has a line break character.
  3427. */
  3428. long GetFirstLineBreakPosition(long pos);
  3429. /**
  3430. Creates a default tabstop array.
  3431. */
  3432. static void InitDefaultTabs();
  3433. /**
  3434. Clears the default tabstop array.
  3435. */
  3436. static void ClearDefaultTabs();
  3437. /**
  3438. Returns the default tabstop array.
  3439. */
  3440. static const wxArrayInt& GetDefaultTabs() { return sm_defaultTabs; }
  3441. /**
  3442. Lays out the floating objects.
  3443. */
  3444. void LayoutFloat(wxDC& dc, wxRichTextDrawingContext& context, const wxRect& rect, const wxRect& parentRect, int style, wxRichTextFloatCollector* floatCollector);
  3445. protected:
  3446. // The lines that make up the wrapped paragraph
  3447. wxRichTextLineList m_cachedLines;
  3448. // Default tabstops
  3449. static wxArrayInt sm_defaultTabs;
  3450. friend class wxRichTextFloatCollector;
  3451. };
  3452. /**
  3453. @class wxRichTextPlainText
  3454. This object represents a single piece of text.
  3455. @library{wxrichtext}
  3456. @category{richtext}
  3457. @see wxRichTextBuffer, wxRichTextCtrl
  3458. */
  3459. class WXDLLIMPEXP_RICHTEXT wxRichTextPlainText: public wxRichTextObject
  3460. {
  3461. DECLARE_DYNAMIC_CLASS(wxRichTextPlainText)
  3462. public:
  3463. // Constructors
  3464. /**
  3465. Constructor.
  3466. */
  3467. wxRichTextPlainText(const wxString& text = wxEmptyString, wxRichTextObject* parent = NULL, wxRichTextAttr* style = NULL);
  3468. /**
  3469. Copy constructor.
  3470. */
  3471. wxRichTextPlainText(const wxRichTextPlainText& obj): wxRichTextObject() { Copy(obj); }
  3472. // Overridables
  3473. virtual bool Draw(wxDC& dc, wxRichTextDrawingContext& context, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style);
  3474. virtual bool Layout(wxDC& dc, wxRichTextDrawingContext& context, const wxRect& rect, const wxRect& parentRect, int style);
  3475. virtual bool AdjustAttributes(wxRichTextAttr& attr, wxRichTextDrawingContext& context);
  3476. virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, wxRichTextDrawingContext& context, int flags, const wxPoint& position = wxPoint(0,0), const wxSize& parentSize = wxDefaultSize, wxArrayInt* partialExtents = NULL) const;
  3477. virtual wxString GetTextForRange(const wxRichTextRange& range) const;
  3478. virtual wxRichTextObject* DoSplit(long pos);
  3479. virtual void CalculateRange(long start, long& end);
  3480. virtual bool DeleteRange(const wxRichTextRange& range);
  3481. virtual bool IsEmpty() const { return m_text.empty(); }
  3482. virtual bool CanMerge(wxRichTextObject* object, wxRichTextDrawingContext& context) const;
  3483. virtual bool Merge(wxRichTextObject* object, wxRichTextDrawingContext& context);
  3484. virtual void Dump(wxTextOutputStream& stream);
  3485. virtual bool CanSplit(wxRichTextDrawingContext& context) const;
  3486. virtual wxRichTextObject* Split(wxRichTextDrawingContext& context);
  3487. /**
  3488. Get the first position from pos that has a line break character.
  3489. */
  3490. long GetFirstLineBreakPosition(long pos);
  3491. /// Does this object take note of paragraph attributes? Text and image objects don't.
  3492. virtual bool UsesParagraphAttributes() const { return false; }
  3493. #if wxUSE_XML
  3494. virtual bool ImportFromXML(wxRichTextBuffer* buffer, wxXmlNode* node, wxRichTextXMLHandler* handler, bool* recurse);
  3495. #endif
  3496. #if wxRICHTEXT_HAVE_DIRECT_OUTPUT
  3497. virtual bool ExportXML(wxOutputStream& stream, int indent, wxRichTextXMLHandler* handler);
  3498. #endif
  3499. #if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT
  3500. virtual bool ExportXML(wxXmlNode* parent, wxRichTextXMLHandler* handler);
  3501. #endif
  3502. virtual wxString GetXMLNodeName() const { return wxT("text"); }
  3503. // Accessors
  3504. /**
  3505. Returns the text.
  3506. */
  3507. const wxString& GetText() const { return m_text; }
  3508. /**
  3509. Sets the text.
  3510. */
  3511. void SetText(const wxString& text) { m_text = text; }
  3512. // Operations
  3513. // Copies the text object,
  3514. void Copy(const wxRichTextPlainText& obj);
  3515. // Clones the text object.
  3516. virtual wxRichTextObject* Clone() const { return new wxRichTextPlainText(*this); }
  3517. private:
  3518. bool DrawTabbedString(wxDC& dc, const wxRichTextAttr& attr, const wxRect& rect, wxString& str, wxCoord& x, wxCoord& y, bool selected);
  3519. protected:
  3520. wxString m_text;
  3521. };
  3522. /**
  3523. @class wxRichTextImageBlock
  3524. This class stores information about an image, in binary in-memory form.
  3525. @library{wxrichtext}
  3526. @category{richtext}
  3527. @see wxRichTextBuffer, wxRichTextCtrl
  3528. */
  3529. class WXDLLIMPEXP_RICHTEXT wxRichTextImageBlock: public wxObject
  3530. {
  3531. public:
  3532. /**
  3533. Constructor.
  3534. */
  3535. wxRichTextImageBlock();
  3536. /**
  3537. Copy constructor.
  3538. */
  3539. wxRichTextImageBlock(const wxRichTextImageBlock& block);
  3540. virtual ~wxRichTextImageBlock();
  3541. /**
  3542. Initialises the block.
  3543. */
  3544. void Init();
  3545. /**
  3546. Clears the block.
  3547. */
  3548. void Clear();
  3549. /**
  3550. Load the original image into a memory block.
  3551. If the image is not a JPEG, we must convert it into a JPEG
  3552. to conserve space.
  3553. If it's not a JPEG we can make use of @a image, already scaled, so we don't have to
  3554. load the image a second time.
  3555. */
  3556. virtual bool MakeImageBlock(const wxString& filename, wxBitmapType imageType,
  3557. wxImage& image, bool convertToJPEG = true);
  3558. /**
  3559. Make an image block from the wxImage in the given
  3560. format.
  3561. */
  3562. virtual bool MakeImageBlock(wxImage& image, wxBitmapType imageType, int quality = 80);
  3563. /**
  3564. Uses a const wxImage for efficiency, but can't set quality (only relevant for JPEG)
  3565. */
  3566. virtual bool MakeImageBlockDefaultQuality(const wxImage& image, wxBitmapType imageType);
  3567. /**
  3568. Makes the image block.
  3569. */
  3570. virtual bool DoMakeImageBlock(const wxImage& image, wxBitmapType imageType);
  3571. /**
  3572. Writes the block to a file.
  3573. */
  3574. bool Write(const wxString& filename);
  3575. /**
  3576. Writes the data in hex to a stream.
  3577. */
  3578. bool WriteHex(wxOutputStream& stream);
  3579. /**
  3580. Reads the data in hex from a stream.
  3581. */
  3582. bool ReadHex(wxInputStream& stream, int length, wxBitmapType imageType);
  3583. /**
  3584. Copy from @a block.
  3585. */
  3586. void Copy(const wxRichTextImageBlock& block);
  3587. // Load a wxImage from the block
  3588. /**
  3589. */
  3590. bool Load(wxImage& image);
  3591. // Operators
  3592. /**
  3593. Assignment operation.
  3594. */
  3595. void operator=(const wxRichTextImageBlock& block);
  3596. // Accessors
  3597. /**
  3598. Returns the raw data.
  3599. */
  3600. unsigned char* GetData() const { return m_data; }
  3601. /**
  3602. Returns the data size in bytes.
  3603. */
  3604. size_t GetDataSize() const { return m_dataSize; }
  3605. /**
  3606. Returns the image type.
  3607. */
  3608. wxBitmapType GetImageType() const { return m_imageType; }
  3609. /**
  3610. */
  3611. void SetData(unsigned char* image) { m_data = image; }
  3612. /**
  3613. Sets the data size.
  3614. */
  3615. void SetDataSize(size_t size) { m_dataSize = size; }
  3616. /**
  3617. Sets the image type.
  3618. */
  3619. void SetImageType(wxBitmapType imageType) { m_imageType = imageType; }
  3620. /**
  3621. Returns @true if the data is non-NULL.
  3622. */
  3623. bool IsOk() const { return GetData() != NULL; }
  3624. bool Ok() const { return IsOk(); }
  3625. /**
  3626. Gets the extension for the block's type.
  3627. */
  3628. wxString GetExtension() const;
  3629. /// Implementation
  3630. /**
  3631. Allocates and reads from a stream as a block of memory.
  3632. */
  3633. static unsigned char* ReadBlock(wxInputStream& stream, size_t size);
  3634. /**
  3635. Allocates and reads from a file as a block of memory.
  3636. */
  3637. static unsigned char* ReadBlock(const wxString& filename, size_t size);
  3638. /**
  3639. Writes a memory block to stream.
  3640. */
  3641. static bool WriteBlock(wxOutputStream& stream, unsigned char* block, size_t size);
  3642. /**
  3643. Writes a memory block to a file.
  3644. */
  3645. static bool WriteBlock(const wxString& filename, unsigned char* block, size_t size);
  3646. protected:
  3647. // Size in bytes of the image stored.
  3648. // This is in the raw, original form such as a JPEG file.
  3649. unsigned char* m_data;
  3650. size_t m_dataSize;
  3651. wxBitmapType m_imageType;
  3652. };
  3653. /**
  3654. @class wxRichTextImage
  3655. This class implements a graphic object.
  3656. @library{wxrichtext}
  3657. @category{richtext}
  3658. @see wxRichTextBuffer, wxRichTextCtrl, wxRichTextImageBlock
  3659. */
  3660. class WXDLLIMPEXP_RICHTEXT wxRichTextImage: public wxRichTextObject
  3661. {
  3662. DECLARE_DYNAMIC_CLASS(wxRichTextImage)
  3663. public:
  3664. // Constructors
  3665. /**
  3666. Default constructor.
  3667. */
  3668. wxRichTextImage(wxRichTextObject* parent = NULL): wxRichTextObject(parent) { Init(); }
  3669. /**
  3670. Creates a wxRichTextImage from a wxImage.
  3671. */
  3672. wxRichTextImage(const wxImage& image, wxRichTextObject* parent = NULL, wxRichTextAttr* charStyle = NULL);
  3673. /**
  3674. Creates a wxRichTextImage from an image block.
  3675. */
  3676. wxRichTextImage(const wxRichTextImageBlock& imageBlock, wxRichTextObject* parent = NULL, wxRichTextAttr* charStyle = NULL);
  3677. /**
  3678. Copy constructor.
  3679. */
  3680. wxRichTextImage(const wxRichTextImage& obj): wxRichTextObject(obj) { Copy(obj); }
  3681. /**
  3682. Destructor.
  3683. */
  3684. ~wxRichTextImage();
  3685. /**
  3686. Initialisation.
  3687. */
  3688. void Init();
  3689. // Overridables
  3690. virtual bool Draw(wxDC& dc, wxRichTextDrawingContext& context, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style);
  3691. virtual bool Layout(wxDC& dc, wxRichTextDrawingContext& context, const wxRect& rect, const wxRect& parentRect, int style);
  3692. virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, wxRichTextDrawingContext& context, int flags, const wxPoint& position = wxPoint(0,0), const wxSize& parentSize = wxDefaultSize, wxArrayInt* partialExtents = NULL) const;
  3693. /**
  3694. Returns the 'natural' size for this object - the image size.
  3695. */
  3696. virtual wxTextAttrSize GetNaturalSize() const;
  3697. virtual bool IsEmpty() const { return false; /* !m_imageBlock.IsOk(); */ }
  3698. virtual bool CanEditProperties() const { return true; }
  3699. virtual bool EditProperties(wxWindow* parent, wxRichTextBuffer* buffer);
  3700. virtual wxString GetPropertiesMenuLabel() const { return wxGetTranslation("&Picture"); }
  3701. virtual bool UsesParagraphAttributes() const { return false; }
  3702. #if wxUSE_XML
  3703. virtual bool ImportFromXML(wxRichTextBuffer* buffer, wxXmlNode* node, wxRichTextXMLHandler* handler, bool* recurse);
  3704. #endif
  3705. #if wxRICHTEXT_HAVE_DIRECT_OUTPUT
  3706. virtual bool ExportXML(wxOutputStream& stream, int indent, wxRichTextXMLHandler* handler);
  3707. #endif
  3708. #if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT
  3709. virtual bool ExportXML(wxXmlNode* parent, wxRichTextXMLHandler* handler);
  3710. #endif
  3711. // Images can be floatable (optionally).
  3712. virtual bool IsFloatable() const { return true; }
  3713. virtual wxString GetXMLNodeName() const { return wxT("image"); }
  3714. // Accessors
  3715. /**
  3716. Returns the image cache (a scaled bitmap).
  3717. */
  3718. const wxBitmap& GetImageCache() const { return m_imageCache; }
  3719. /**
  3720. Sets the image cache.
  3721. */
  3722. void SetImageCache(const wxBitmap& bitmap) { m_imageCache = bitmap; m_originalImageSize = wxSize(bitmap.GetWidth(), bitmap.GetHeight()); }
  3723. /**
  3724. Resets the image cache.
  3725. */
  3726. void ResetImageCache() { m_imageCache = wxNullBitmap; m_originalImageSize = wxSize(-1, -1); }
  3727. /**
  3728. Returns the image block containing the raw data.
  3729. */
  3730. wxRichTextImageBlock& GetImageBlock() { return m_imageBlock; }
  3731. // Operations
  3732. /**
  3733. Copies the image object.
  3734. */
  3735. void Copy(const wxRichTextImage& obj);
  3736. /**
  3737. Clones the image object.
  3738. */
  3739. virtual wxRichTextObject* Clone() const { return new wxRichTextImage(*this); }
  3740. /**
  3741. Creates a cached image at the required size.
  3742. */
  3743. virtual bool LoadImageCache(wxDC& dc, bool resetCache = false, const wxSize& parentSize = wxDefaultSize);
  3744. /**
  3745. Gets the original image size.
  3746. */
  3747. wxSize GetOriginalImageSize() const { return m_originalImageSize; }
  3748. /**
  3749. Sets the original image size.
  3750. */
  3751. void SetOriginalImageSize(const wxSize& sz) { m_originalImageSize = sz; }
  3752. protected:
  3753. wxRichTextImageBlock m_imageBlock;
  3754. wxBitmap m_imageCache;
  3755. wxSize m_originalImageSize;
  3756. };
  3757. class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextCommand;
  3758. class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextAction;
  3759. /**
  3760. @class wxRichTextBuffer
  3761. This is a kind of paragraph layout box, used to represent the whole buffer.
  3762. @library{wxrichtext}
  3763. @category{richtext}
  3764. @see wxRichTextParagraphLayoutBox, wxRichTextCtrl
  3765. */
  3766. class WXDLLIMPEXP_RICHTEXT wxRichTextBuffer: public wxRichTextParagraphLayoutBox
  3767. {
  3768. DECLARE_DYNAMIC_CLASS(wxRichTextBuffer)
  3769. public:
  3770. // Constructors
  3771. /**
  3772. Default constructor.
  3773. */
  3774. wxRichTextBuffer() { Init(); }
  3775. /**
  3776. Copy constructor.
  3777. */
  3778. wxRichTextBuffer(const wxRichTextBuffer& obj): wxRichTextParagraphLayoutBox() { Init(); Copy(obj); }
  3779. virtual ~wxRichTextBuffer() ;
  3780. // Accessors
  3781. /**
  3782. Returns the command processor.
  3783. A text buffer always creates its own command processor when it is initialized.
  3784. */
  3785. wxCommandProcessor* GetCommandProcessor() const { return m_commandProcessor; }
  3786. /**
  3787. Sets style sheet, if any. This will allow the application to use named character and paragraph
  3788. styles found in the style sheet.
  3789. Neither the buffer nor the control owns the style sheet so must be deleted by the application.
  3790. */
  3791. void SetStyleSheet(wxRichTextStyleSheet* styleSheet) { m_styleSheet = styleSheet; }
  3792. /**
  3793. Returns the style sheet.
  3794. */
  3795. virtual wxRichTextStyleSheet* GetStyleSheet() const { return m_styleSheet; }
  3796. /**
  3797. Sets the style sheet and sends a notification of the change.
  3798. */
  3799. bool SetStyleSheetAndNotify(wxRichTextStyleSheet* sheet);
  3800. /**
  3801. Pushes the style sheet to the top of the style sheet stack.
  3802. */
  3803. bool PushStyleSheet(wxRichTextStyleSheet* styleSheet);
  3804. /**
  3805. Pops the style sheet from the top of the style sheet stack.
  3806. */
  3807. wxRichTextStyleSheet* PopStyleSheet();
  3808. /**
  3809. Returns the table storing fonts, for quick access and font reuse.
  3810. */
  3811. wxRichTextFontTable& GetFontTable() { return m_fontTable; }
  3812. /**
  3813. Returns the table storing fonts, for quick access and font reuse.
  3814. */
  3815. const wxRichTextFontTable& GetFontTable() const { return m_fontTable; }
  3816. /**
  3817. Sets table storing fonts, for quick access and font reuse.
  3818. */
  3819. void SetFontTable(const wxRichTextFontTable& table) { m_fontTable = table; }
  3820. /**
  3821. Sets the scale factor for displaying fonts, for example for more comfortable
  3822. editing.
  3823. */
  3824. void SetFontScale(double fontScale);
  3825. /**
  3826. Returns the scale factor for displaying fonts, for example for more comfortable
  3827. editing.
  3828. */
  3829. double GetFontScale() const { return m_fontScale; }
  3830. /**
  3831. Sets the scale factor for displaying certain dimensions such as indentation and
  3832. inter-paragraph spacing. This can be useful when editing in a small control
  3833. where you still want legible text, but a minimum of wasted white space.
  3834. */
  3835. void SetDimensionScale(double dimScale);
  3836. /**
  3837. Returns the scale factor for displaying certain dimensions such as indentation
  3838. and inter-paragraph spacing.
  3839. */
  3840. double GetDimensionScale() const { return m_dimensionScale; }
  3841. // Operations
  3842. /**
  3843. Initialisation.
  3844. */
  3845. void Init();
  3846. /**
  3847. Clears the buffer, adds an empty paragraph, and clears the command processor.
  3848. */
  3849. virtual void ResetAndClearCommands();
  3850. #if wxUSE_FFILE && wxUSE_STREAMS
  3851. //@{
  3852. /**
  3853. Loads content from a file.
  3854. Not all handlers will implement file loading.
  3855. */
  3856. virtual bool LoadFile(const wxString& filename, wxRichTextFileType type = wxRICHTEXT_TYPE_ANY);
  3857. //@}
  3858. //@{
  3859. /**
  3860. Saves content to a file.
  3861. Not all handlers will implement file saving.
  3862. */
  3863. virtual bool SaveFile(const wxString& filename, wxRichTextFileType type = wxRICHTEXT_TYPE_ANY);
  3864. //@}
  3865. #endif // wxUSE_FFILE
  3866. #if wxUSE_STREAMS
  3867. //@{
  3868. /**
  3869. Loads content from a stream.
  3870. Not all handlers will implement loading from a stream.
  3871. */
  3872. virtual bool LoadFile(wxInputStream& stream, wxRichTextFileType type = wxRICHTEXT_TYPE_ANY);
  3873. //@}
  3874. //@{
  3875. /**
  3876. Saves content to a stream.
  3877. Not all handlers will implement saving to a stream.
  3878. */
  3879. virtual bool SaveFile(wxOutputStream& stream, wxRichTextFileType type = wxRICHTEXT_TYPE_ANY);
  3880. //@}
  3881. #endif // wxUSE_STREAMS
  3882. /**
  3883. Sets the handler flags, controlling loading and saving.
  3884. */
  3885. void SetHandlerFlags(int flags) { m_handlerFlags = flags; }
  3886. /**
  3887. Gets the handler flags, controlling loading and saving.
  3888. */
  3889. int GetHandlerFlags() const { return m_handlerFlags; }
  3890. /**
  3891. Convenience function to add a paragraph of text.
  3892. */
  3893. virtual wxRichTextRange AddParagraph(const wxString& text, wxRichTextAttr* paraStyle = NULL) { Modify(); return wxRichTextParagraphLayoutBox::AddParagraph(text, paraStyle); }
  3894. /**
  3895. Begin collapsing undo/redo commands. Note that this may not work properly
  3896. if combining commands that delete or insert content, changing ranges for
  3897. subsequent actions.
  3898. @a cmdName should be the name of the combined command that will appear
  3899. next to Undo and Redo in the edit menu.
  3900. */
  3901. virtual bool BeginBatchUndo(const wxString& cmdName);
  3902. /**
  3903. End collapsing undo/redo commands.
  3904. */
  3905. virtual bool EndBatchUndo();
  3906. /**
  3907. Returns @true if we are collapsing commands.
  3908. */
  3909. virtual bool BatchingUndo() const { return m_batchedCommandDepth > 0; }
  3910. /**
  3911. Submit the action immediately, or delay according to whether collapsing is on.
  3912. */
  3913. virtual bool SubmitAction(wxRichTextAction* action);
  3914. /**
  3915. Returns the collapsed command.
  3916. */
  3917. virtual wxRichTextCommand* GetBatchedCommand() const { return m_batchedCommand; }
  3918. /**
  3919. Begin suppressing undo/redo commands. The way undo is suppressed may be implemented
  3920. differently by each command. If not dealt with by a command implementation, then
  3921. it will be implemented automatically by not storing the command in the undo history
  3922. when the action is submitted to the command processor.
  3923. */
  3924. virtual bool BeginSuppressUndo();
  3925. /**
  3926. End suppressing undo/redo commands.
  3927. */
  3928. virtual bool EndSuppressUndo();
  3929. /**
  3930. Are we suppressing undo??
  3931. */
  3932. virtual bool SuppressingUndo() const { return m_suppressUndo > 0; }
  3933. /**
  3934. Copy the range to the clipboard.
  3935. */
  3936. virtual bool CopyToClipboard(const wxRichTextRange& range);
  3937. /**
  3938. Paste the clipboard content to the buffer.
  3939. */
  3940. virtual bool PasteFromClipboard(long position);
  3941. /**
  3942. Returns @true if we can paste from the clipboard.
  3943. */
  3944. virtual bool CanPasteFromClipboard() const;
  3945. /**
  3946. Begin using a style.
  3947. */
  3948. virtual bool BeginStyle(const wxRichTextAttr& style);
  3949. /**
  3950. End the style.
  3951. */
  3952. virtual bool EndStyle();
  3953. /**
  3954. End all styles.
  3955. */
  3956. virtual bool EndAllStyles();
  3957. /**
  3958. Clears the style stack.
  3959. */
  3960. virtual void ClearStyleStack();
  3961. /**
  3962. Returns the size of the style stack, for example to check correct nesting.
  3963. */
  3964. virtual size_t GetStyleStackSize() const { return m_attributeStack.GetCount(); }
  3965. /**
  3966. Begins using bold.
  3967. */
  3968. bool BeginBold();
  3969. /**
  3970. Ends using bold.
  3971. */
  3972. bool EndBold() { return EndStyle(); }
  3973. /**
  3974. Begins using italic.
  3975. */
  3976. bool BeginItalic();
  3977. /**
  3978. Ends using italic.
  3979. */
  3980. bool EndItalic() { return EndStyle(); }
  3981. /**
  3982. Begins using underline.
  3983. */
  3984. bool BeginUnderline();
  3985. /**
  3986. Ends using underline.
  3987. */
  3988. bool EndUnderline() { return EndStyle(); }
  3989. /**
  3990. Begins using point size.
  3991. */
  3992. bool BeginFontSize(int pointSize);
  3993. /**
  3994. Ends using point size.
  3995. */
  3996. bool EndFontSize() { return EndStyle(); }
  3997. /**
  3998. Begins using this font.
  3999. */
  4000. bool BeginFont(const wxFont& font);
  4001. /**
  4002. Ends using a font.
  4003. */
  4004. bool EndFont() { return EndStyle(); }
  4005. /**
  4006. Begins using this colour.
  4007. */
  4008. bool BeginTextColour(const wxColour& colour);
  4009. /**
  4010. Ends using a colour.
  4011. */
  4012. bool EndTextColour() { return EndStyle(); }
  4013. /**
  4014. Begins using alignment.
  4015. */
  4016. bool BeginAlignment(wxTextAttrAlignment alignment);
  4017. /**
  4018. Ends alignment.
  4019. */
  4020. bool EndAlignment() { return EndStyle(); }
  4021. /**
  4022. Begins using @a leftIndent for the left indent, and optionally @a leftSubIndent for
  4023. the sub-indent. Both are expressed in tenths of a millimetre.
  4024. The sub-indent is an offset from the left of the paragraph, and is used for all
  4025. but the first line in a paragraph. A positive value will cause the first line to appear
  4026. to the left of the subsequent lines, and a negative value will cause the first line to be
  4027. indented relative to the subsequent lines.
  4028. */
  4029. bool BeginLeftIndent(int leftIndent, int leftSubIndent = 0);
  4030. /**
  4031. Ends left indent.
  4032. */
  4033. bool EndLeftIndent() { return EndStyle(); }
  4034. /**
  4035. Begins a right indent, specified in tenths of a millimetre.
  4036. */
  4037. bool BeginRightIndent(int rightIndent);
  4038. /**
  4039. Ends right indent.
  4040. */
  4041. bool EndRightIndent() { return EndStyle(); }
  4042. /**
  4043. Begins paragraph spacing; pass the before-paragraph and after-paragraph spacing
  4044. in tenths of a millimetre.
  4045. */
  4046. bool BeginParagraphSpacing(int before, int after);
  4047. /**
  4048. Ends paragraph spacing.
  4049. */
  4050. bool EndParagraphSpacing() { return EndStyle(); }
  4051. /**
  4052. Begins line spacing using the specified value. @e spacing is a multiple, where
  4053. 10 means single-spacing, 15 means 1.5 spacing, and 20 means double spacing.
  4054. The ::wxTextAttrLineSpacing enumeration values are defined for convenience.
  4055. */
  4056. bool BeginLineSpacing(int lineSpacing);
  4057. /**
  4058. Ends line spacing.
  4059. */
  4060. bool EndLineSpacing() { return EndStyle(); }
  4061. /**
  4062. Begins numbered bullet.
  4063. This call will be needed for each item in the list, and the
  4064. application should take care of incrementing the numbering.
  4065. @a bulletNumber is a number, usually starting with 1.
  4066. @a leftIndent and @a leftSubIndent are values in tenths of a millimetre.
  4067. @a bulletStyle is a bitlist of the following values:
  4068. wxRichTextBuffer uses indentation to render a bulleted item.
  4069. The left indent is the distance between the margin and the bullet.
  4070. The content of the paragraph, including the first line, starts
  4071. at leftMargin + leftSubIndent.
  4072. So the distance between the left edge of the bullet and the
  4073. left of the actual paragraph is leftSubIndent.
  4074. */
  4075. bool BeginNumberedBullet(int bulletNumber, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_ARABIC|wxTEXT_ATTR_BULLET_STYLE_PERIOD);
  4076. /**
  4077. Ends numbered bullet.
  4078. */
  4079. bool EndNumberedBullet() { return EndStyle(); }
  4080. /**
  4081. Begins applying a symbol bullet, using a character from the current font.
  4082. See BeginNumberedBullet() for an explanation of how indentation is used
  4083. to render the bulleted paragraph.
  4084. */
  4085. bool BeginSymbolBullet(const wxString& symbol, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_SYMBOL);
  4086. /**
  4087. Ends symbol bullet.
  4088. */
  4089. bool EndSymbolBullet() { return EndStyle(); }
  4090. /**
  4091. Begins applying a standard bullet, using one of the standard bullet names
  4092. (currently @c standard/circle or @c standard/square.
  4093. See BeginNumberedBullet() for an explanation of how indentation is used to
  4094. render the bulleted paragraph.
  4095. */
  4096. bool BeginStandardBullet(const wxString& bulletName, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_STANDARD);
  4097. /**
  4098. Ends standard bullet.
  4099. */
  4100. bool EndStandardBullet() { return EndStyle(); }
  4101. /**
  4102. Begins named character style.
  4103. */
  4104. bool BeginCharacterStyle(const wxString& characterStyle);
  4105. /**
  4106. Ends named character style.
  4107. */
  4108. bool EndCharacterStyle() { return EndStyle(); }
  4109. /**
  4110. Begins named paragraph style.
  4111. */
  4112. bool BeginParagraphStyle(const wxString& paragraphStyle);
  4113. /**
  4114. Ends named character style.
  4115. */
  4116. bool EndParagraphStyle() { return EndStyle(); }
  4117. /**
  4118. Begins named list style.
  4119. Optionally, you can also pass a level and a number.
  4120. */
  4121. bool BeginListStyle(const wxString& listStyle, int level = 1, int number = 1);
  4122. /**
  4123. Ends named character style.
  4124. */
  4125. bool EndListStyle() { return EndStyle(); }
  4126. /**
  4127. Begins applying wxTEXT_ATTR_URL to the content.
  4128. Pass a URL and optionally, a character style to apply, since it is common
  4129. to mark a URL with a familiar style such as blue text with underlining.
  4130. */
  4131. bool BeginURL(const wxString& url, const wxString& characterStyle = wxEmptyString);
  4132. /**
  4133. Ends URL.
  4134. */
  4135. bool EndURL() { return EndStyle(); }
  4136. // Event handling
  4137. /**
  4138. Adds an event handler.
  4139. A buffer associated with a control has the control as the only event handler,
  4140. but the application is free to add more if further notification is required.
  4141. All handlers are notified of an event originating from the buffer, such as
  4142. the replacement of a style sheet during loading.
  4143. The buffer never deletes any of the event handlers, unless RemoveEventHandler()
  4144. is called with @true as the second argument.
  4145. */
  4146. bool AddEventHandler(wxEvtHandler* handler);
  4147. /**
  4148. Removes an event handler from the buffer's list of handlers, deleting the
  4149. object if @a deleteHandler is @true.
  4150. */
  4151. bool RemoveEventHandler(wxEvtHandler* handler, bool deleteHandler = false);
  4152. /**
  4153. Clear event handlers.
  4154. */
  4155. void ClearEventHandlers();
  4156. /**
  4157. Send event to event handlers. If sendToAll is true, will send to all event handlers,
  4158. otherwise will stop at the first successful one.
  4159. */
  4160. bool SendEvent(wxEvent& event, bool sendToAll = true);
  4161. // Implementation
  4162. virtual int HitTest(wxDC& dc, wxRichTextDrawingContext& context, const wxPoint& pt, long& textPosition, wxRichTextObject** obj, wxRichTextObject** contextObj, int flags = 0);
  4163. /**
  4164. Copies the buffer.
  4165. */
  4166. void Copy(const wxRichTextBuffer& obj);
  4167. /**
  4168. Assignment operator.
  4169. */
  4170. void operator= (const wxRichTextBuffer& obj) { Copy(obj); }
  4171. /**
  4172. Clones the buffer.
  4173. */
  4174. virtual wxRichTextObject* Clone() const { return new wxRichTextBuffer(*this); }
  4175. /**
  4176. Submits a command to insert paragraphs.
  4177. */
  4178. bool InsertParagraphsWithUndo(long pos, const wxRichTextParagraphLayoutBox& paragraphs, wxRichTextCtrl* ctrl, int flags = 0);
  4179. /**
  4180. Submits a command to insert the given text.
  4181. */
  4182. bool InsertTextWithUndo(long pos, const wxString& text, wxRichTextCtrl* ctrl, int flags = 0);
  4183. /**
  4184. Submits a command to insert a newline.
  4185. */
  4186. bool InsertNewlineWithUndo(long pos, wxRichTextCtrl* ctrl, int flags = 0);
  4187. /**
  4188. Submits a command to insert the given image.
  4189. */
  4190. bool InsertImageWithUndo(long pos, const wxRichTextImageBlock& imageBlock, wxRichTextCtrl* ctrl, int flags = 0,
  4191. const wxRichTextAttr& textAttr = wxRichTextAttr());
  4192. /**
  4193. Submits a command to insert an object.
  4194. */
  4195. wxRichTextObject* InsertObjectWithUndo(long pos, wxRichTextObject *object, wxRichTextCtrl* ctrl, int flags);
  4196. /**
  4197. Submits a command to delete this range.
  4198. */
  4199. bool DeleteRangeWithUndo(const wxRichTextRange& range, wxRichTextCtrl* ctrl);
  4200. /**
  4201. Mark modified.
  4202. */
  4203. void Modify(bool modify = true) { m_modified = modify; }
  4204. /**
  4205. Returns @true if the buffer was modified.
  4206. */
  4207. bool IsModified() const { return m_modified; }
  4208. //@{
  4209. /**
  4210. Dumps contents of buffer for debugging purposes.
  4211. */
  4212. virtual void Dump();
  4213. virtual void Dump(wxTextOutputStream& stream) { wxRichTextParagraphLayoutBox::Dump(stream); }
  4214. //@}
  4215. /**
  4216. Returns the file handlers.
  4217. */
  4218. static wxList& GetHandlers() { return sm_handlers; }
  4219. /**
  4220. Adds a file handler to the end.
  4221. */
  4222. static void AddHandler(wxRichTextFileHandler *handler);
  4223. /**
  4224. Inserts a file handler at the front.
  4225. */
  4226. static void InsertHandler(wxRichTextFileHandler *handler);
  4227. /**
  4228. Removes a file handler.
  4229. */
  4230. static bool RemoveHandler(const wxString& name);
  4231. /**
  4232. Finds a file handler by name.
  4233. */
  4234. static wxRichTextFileHandler *FindHandler(const wxString& name);
  4235. /**
  4236. Finds a file handler by extension and type.
  4237. */
  4238. static wxRichTextFileHandler *FindHandler(const wxString& extension, wxRichTextFileType imageType);
  4239. /**
  4240. Finds a handler by filename or, if supplied, type.
  4241. */
  4242. static wxRichTextFileHandler *FindHandlerFilenameOrType(const wxString& filename,
  4243. wxRichTextFileType imageType);
  4244. /**
  4245. Finds a handler by type.
  4246. */
  4247. static wxRichTextFileHandler *FindHandler(wxRichTextFileType imageType);
  4248. /**
  4249. Gets a wildcard incorporating all visible handlers. If @a types is present,
  4250. it will be filled with the file type corresponding to each filter. This can be
  4251. used to determine the type to pass to LoadFile given a selected filter.
  4252. */
  4253. static wxString GetExtWildcard(bool combine = false, bool save = false, wxArrayInt* types = NULL);
  4254. /**
  4255. Clean up file handlers.
  4256. */
  4257. static void CleanUpHandlers();
  4258. /**
  4259. Initialise the standard file handlers.
  4260. Currently, only the plain text loading/saving handler is initialised by default.
  4261. */
  4262. static void InitStandardHandlers();
  4263. /**
  4264. Returns the drawing handlers.
  4265. */
  4266. static wxList& GetDrawingHandlers() { return sm_drawingHandlers; }
  4267. /**
  4268. Adds a drawing handler to the end.
  4269. */
  4270. static void AddDrawingHandler(wxRichTextDrawingHandler *handler);
  4271. /**
  4272. Inserts a drawing handler at the front.
  4273. */
  4274. static void InsertDrawingHandler(wxRichTextDrawingHandler *handler);
  4275. /**
  4276. Removes a drawing handler.
  4277. */
  4278. static bool RemoveDrawingHandler(const wxString& name);
  4279. /**
  4280. Finds a drawing handler by name.
  4281. */
  4282. static wxRichTextDrawingHandler *FindDrawingHandler(const wxString& name);
  4283. /**
  4284. Clean up drawing handlers.
  4285. */
  4286. static void CleanUpDrawingHandlers();
  4287. /**
  4288. Returns the field types.
  4289. */
  4290. static wxRichTextFieldTypeHashMap& GetFieldTypes() { return sm_fieldTypes; }
  4291. /**
  4292. Adds a field type.
  4293. @see RemoveFieldType(), FindFieldType(), wxRichTextField, wxRichTextFieldType, wxRichTextFieldTypeStandard
  4294. */
  4295. static void AddFieldType(wxRichTextFieldType *fieldType);
  4296. /**
  4297. Removes a field type by name.
  4298. @see AddFieldType(), FindFieldType(), wxRichTextField, wxRichTextFieldType, wxRichTextFieldTypeStandard
  4299. */
  4300. static bool RemoveFieldType(const wxString& name);
  4301. /**
  4302. Finds a field type by name.
  4303. @see RemoveFieldType(), AddFieldType(), wxRichTextField, wxRichTextFieldType, wxRichTextFieldTypeStandard
  4304. */
  4305. static wxRichTextFieldType *FindFieldType(const wxString& name);
  4306. /**
  4307. Cleans up field types.
  4308. */
  4309. static void CleanUpFieldTypes();
  4310. /**
  4311. Returns the renderer object.
  4312. */
  4313. static wxRichTextRenderer* GetRenderer() { return sm_renderer; }
  4314. /**
  4315. Sets @a renderer as the object to be used to render certain aspects of the
  4316. content, such as bullets.
  4317. You can override default rendering by deriving a new class from
  4318. wxRichTextRenderer or wxRichTextStdRenderer, overriding one or more
  4319. virtual functions, and setting an instance of the class using this function.
  4320. */
  4321. static void SetRenderer(wxRichTextRenderer* renderer);
  4322. /**
  4323. Returns the minimum margin between bullet and paragraph in 10ths of a mm.
  4324. */
  4325. static int GetBulletRightMargin() { return sm_bulletRightMargin; }
  4326. /**
  4327. Sets the minimum margin between bullet and paragraph in 10ths of a mm.
  4328. */
  4329. static void SetBulletRightMargin(int margin) { sm_bulletRightMargin = margin; }
  4330. /**
  4331. Returns the factor to multiply by character height to get a reasonable bullet size.
  4332. */
  4333. static float GetBulletProportion() { return sm_bulletProportion; }
  4334. /**
  4335. Sets the factor to multiply by character height to get a reasonable bullet size.
  4336. */
  4337. static void SetBulletProportion(float prop) { sm_bulletProportion = prop; }
  4338. /**
  4339. Returns the scale factor for calculating dimensions.
  4340. */
  4341. double GetScale() const { return m_scale; }
  4342. /**
  4343. Sets the scale factor for calculating dimensions.
  4344. */
  4345. void SetScale(double scale) { m_scale = scale; }
  4346. /**
  4347. Sets the floating layout mode. Pass @false to speed up editing by not performing
  4348. floating layout. This setting affects all buffers.
  4349. */
  4350. static void SetFloatingLayoutMode(bool mode) { sm_floatingLayoutMode = mode; }
  4351. /**
  4352. Returns the floating layout mode. The default is @true, where objects
  4353. are laid out according to their floating status.
  4354. */
  4355. static bool GetFloatingLayoutMode() { return sm_floatingLayoutMode; }
  4356. protected:
  4357. /// Command processor
  4358. wxCommandProcessor* m_commandProcessor;
  4359. /// Table storing fonts
  4360. wxRichTextFontTable m_fontTable;
  4361. /// Has been modified?
  4362. bool m_modified;
  4363. /// Collapsed command stack
  4364. int m_batchedCommandDepth;
  4365. /// Name for collapsed command
  4366. wxString m_batchedCommandsName;
  4367. /// Current collapsed command accumulating actions
  4368. wxRichTextCommand* m_batchedCommand;
  4369. /// Whether to suppress undo
  4370. int m_suppressUndo;
  4371. /// Style sheet, if any
  4372. wxRichTextStyleSheet* m_styleSheet;
  4373. /// List of event handlers that will be notified of events
  4374. wxList m_eventHandlers;
  4375. /// Stack of attributes for convenience functions
  4376. wxList m_attributeStack;
  4377. /// Flags to be passed to handlers
  4378. int m_handlerFlags;
  4379. /// File handlers
  4380. static wxList sm_handlers;
  4381. /// Drawing handlers
  4382. static wxList sm_drawingHandlers;
  4383. /// Field types
  4384. static wxRichTextFieldTypeHashMap sm_fieldTypes;
  4385. /// Renderer
  4386. static wxRichTextRenderer* sm_renderer;
  4387. /// Minimum margin between bullet and paragraph in 10ths of a mm
  4388. static int sm_bulletRightMargin;
  4389. /// Factor to multiply by character height to get a reasonable bullet size
  4390. static float sm_bulletProportion;
  4391. /// Floating layout mode, @true by default
  4392. static bool sm_floatingLayoutMode;
  4393. /// Scaling factor in use: needed to calculate correct dimensions when printing
  4394. double m_scale;
  4395. /// Font scale for adjusting the text size when editing
  4396. double m_fontScale;
  4397. /// Dimension scale for reducing redundant whitespace when editing
  4398. double m_dimensionScale;
  4399. };
  4400. /**
  4401. @class wxRichTextCell
  4402. wxRichTextCell is the cell in a table.
  4403. */
  4404. class WXDLLIMPEXP_RICHTEXT wxRichTextCell: public wxRichTextBox
  4405. {
  4406. DECLARE_DYNAMIC_CLASS(wxRichTextCell)
  4407. public:
  4408. // Constructors
  4409. /**
  4410. Default constructor; optionally pass the parent object.
  4411. */
  4412. wxRichTextCell(wxRichTextObject* parent = NULL);
  4413. /**
  4414. Copy constructor.
  4415. */
  4416. wxRichTextCell(const wxRichTextCell& obj): wxRichTextBox() { Copy(obj); }
  4417. // Overridables
  4418. virtual bool Draw(wxDC& dc, wxRichTextDrawingContext& context, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style);
  4419. virtual int HitTest(wxDC& dc, wxRichTextDrawingContext& context, const wxPoint& pt, long& textPosition, wxRichTextObject** obj, wxRichTextObject** contextObj, int flags = 0);
  4420. virtual bool AdjustAttributes(wxRichTextAttr& attr, wxRichTextDrawingContext& context);
  4421. virtual wxString GetXMLNodeName() const { return wxT("cell"); }
  4422. virtual bool CanEditProperties() const { return true; }
  4423. virtual bool EditProperties(wxWindow* parent, wxRichTextBuffer* buffer);
  4424. virtual wxString GetPropertiesMenuLabel() const { return wxGetTranslation("&Cell"); }
  4425. // Accessors
  4426. int GetColSpan() const;
  4427. void SetColSpan(long span) { GetProperties().SetProperty(wxT("colspan"), span); }
  4428. int GetRowSpan() const;
  4429. void SetRowSpan(long span) { GetProperties().SetProperty(wxT("rowspan"), span); }
  4430. // Operations
  4431. virtual wxRichTextObject* Clone() const { return new wxRichTextCell(*this); }
  4432. void Copy(const wxRichTextCell& obj);
  4433. protected:
  4434. };
  4435. /**
  4436. @class wxRichTextTable
  4437. wxRichTextTable represents a table with arbitrary columns and rows.
  4438. */
  4439. WX_DEFINE_ARRAY_PTR(wxRichTextObject*, wxRichTextObjectPtrArray);
  4440. WX_DECLARE_USER_EXPORTED_OBJARRAY(wxRichTextObjectPtrArray, wxRichTextObjectPtrArrayArray, WXDLLIMPEXP_RICHTEXT);
  4441. class WXDLLIMPEXP_RICHTEXT wxRichTextTable: public wxRichTextBox
  4442. {
  4443. DECLARE_DYNAMIC_CLASS(wxRichTextTable)
  4444. public:
  4445. // Constructors
  4446. /**
  4447. Default constructor; optionally pass the parent object.
  4448. */
  4449. wxRichTextTable(wxRichTextObject* parent = NULL);
  4450. /**
  4451. Copy constructor.
  4452. */
  4453. wxRichTextTable(const wxRichTextTable& obj): wxRichTextBox() { Copy(obj); }
  4454. // Overridables
  4455. virtual bool Draw(wxDC& dc, wxRichTextDrawingContext& context, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style);
  4456. virtual int HitTest(wxDC& dc, wxRichTextDrawingContext& context, const wxPoint& pt, long& textPosition, wxRichTextObject** obj, wxRichTextObject** contextObj, int flags = 0);
  4457. virtual bool AdjustAttributes(wxRichTextAttr& attr, wxRichTextDrawingContext& context);
  4458. virtual wxString GetXMLNodeName() const { return wxT("table"); }
  4459. virtual bool Layout(wxDC& dc, wxRichTextDrawingContext& context, const wxRect& rect, const wxRect& parentRect, int style);
  4460. virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, wxRichTextDrawingContext& context, int flags, const wxPoint& position = wxPoint(0,0), const wxSize& parentSize = wxDefaultSize, wxArrayInt* partialExtents = NULL) const;
  4461. virtual bool DeleteRange(const wxRichTextRange& range);
  4462. virtual wxString GetTextForRange(const wxRichTextRange& range) const;
  4463. #if wxUSE_XML
  4464. virtual bool ImportFromXML(wxRichTextBuffer* buffer, wxXmlNode* node, wxRichTextXMLHandler* handler, bool* recurse);
  4465. #endif
  4466. #if wxRICHTEXT_HAVE_DIRECT_OUTPUT
  4467. virtual bool ExportXML(wxOutputStream& stream, int indent, wxRichTextXMLHandler* handler);
  4468. #endif
  4469. #if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT
  4470. virtual bool ExportXML(wxXmlNode* parent, wxRichTextXMLHandler* handler);
  4471. #endif
  4472. virtual bool FindPosition(wxDC& dc, wxRichTextDrawingContext& context, long index, wxPoint& pt, int* height, bool forceLineStart);
  4473. virtual void CalculateRange(long start, long& end);
  4474. // Can this object handle the selections of its children? FOr example, a table.
  4475. virtual bool HandlesChildSelections() const { return true; }
  4476. /// Returns a selection object specifying the selections between start and end character positions.
  4477. /// For example, a table would deduce what cells (of range length 1) are selected when dragging across the table.
  4478. virtual wxRichTextSelection GetSelection(long start, long end) const;
  4479. virtual bool CanEditProperties() const { return true; }
  4480. virtual bool EditProperties(wxWindow* parent, wxRichTextBuffer* buffer);
  4481. virtual wxString GetPropertiesMenuLabel() const { return wxGetTranslation("&Table"); }
  4482. // Returns true if objects of this class can accept the focus, i.e. a call to SetFocusObject
  4483. // is possible. For example, containers supporting text, such as a text box object, can accept the focus,
  4484. // but a table can't (set the focus to individual cells instead).
  4485. virtual bool AcceptsFocus() const { return false; }
  4486. // Accessors
  4487. /**
  4488. Returns the cells array.
  4489. */
  4490. const wxRichTextObjectPtrArrayArray& GetCells() const { return m_cells; }
  4491. /**
  4492. Returns the cells array.
  4493. */
  4494. wxRichTextObjectPtrArrayArray& GetCells() { return m_cells; }
  4495. /**
  4496. Returns the row count.
  4497. */
  4498. int GetRowCount() const { return m_rowCount; }
  4499. /**
  4500. Sets the row count.
  4501. */
  4502. void SetRowCount(int count) { m_rowCount = count; }
  4503. /**
  4504. Returns the column count.
  4505. */
  4506. int GetColumnCount() const { return m_colCount; }
  4507. /**
  4508. Sets the column count.
  4509. */
  4510. void SetColumnCount(int count) { m_colCount = count; }
  4511. /**
  4512. Returns the cell at the given row/column position.
  4513. */
  4514. virtual wxRichTextCell* GetCell(int row, int col) const;
  4515. /**
  4516. Returns the cell at the given character position (in the range of the table).
  4517. */
  4518. virtual wxRichTextCell* GetCell(long pos) const;
  4519. /**
  4520. Returns the row/column for a given character position.
  4521. */
  4522. virtual bool GetCellRowColumnPosition(long pos, int& row, int& col) const;
  4523. /**
  4524. Returns the coordinates of the cell with keyboard focus, or (-1,-1) if none.
  4525. */
  4526. virtual wxPosition GetFocusedCell() const;
  4527. // Operations
  4528. /**
  4529. Clears the table.
  4530. */
  4531. virtual void ClearTable();
  4532. /**
  4533. Creates a table of the given dimensions.
  4534. */
  4535. virtual bool CreateTable(int rows, int cols);
  4536. /**
  4537. Sets the attributes for the cells specified by the selection.
  4538. */
  4539. virtual bool SetCellStyle(const wxRichTextSelection& selection, const wxRichTextAttr& style, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO);
  4540. /**
  4541. Deletes rows from the given row position.
  4542. */
  4543. virtual bool DeleteRows(int startRow, int noRows = 1);
  4544. /**
  4545. Deletes columns from the given column position.
  4546. */
  4547. virtual bool DeleteColumns(int startCol, int noCols = 1);
  4548. /**
  4549. Adds rows from the given row position.
  4550. */
  4551. virtual bool AddRows(int startRow, int noRows = 1, const wxRichTextAttr& attr = wxRichTextAttr());
  4552. /**
  4553. Adds columns from the given column position.
  4554. */
  4555. virtual bool AddColumns(int startCol, int noCols = 1, const wxRichTextAttr& attr = wxRichTextAttr());
  4556. // Makes a clone of this object.
  4557. virtual wxRichTextObject* Clone() const { return new wxRichTextTable(*this); }
  4558. // Copies this object.
  4559. void Copy(const wxRichTextTable& obj);
  4560. protected:
  4561. int m_rowCount;
  4562. int m_colCount;
  4563. // An array of rows, each of which is a wxRichTextObjectPtrArray containing
  4564. // the cell objects. The cell objects are also children of this object.
  4565. // Problem: if boxes are immediate children of a box, this will cause problems
  4566. // with wxRichTextParagraphLayoutBox functions (and functions elsewhere) that
  4567. // expect to find just paragraphs. May have to adjust the way we handle the
  4568. // hierarchy to accept non-paragraph objects in a paragraph layout box.
  4569. // We'll be overriding much wxRichTextParagraphLayoutBox functionality so this
  4570. // may not be such a problem. Perhaps the table should derive from a different
  4571. // class?
  4572. wxRichTextObjectPtrArrayArray m_cells;
  4573. };
  4574. /** @class wxRichTextTableBlock
  4575. Stores the coordinates for a block of cells.
  4576. */
  4577. class WXDLLIMPEXP_RICHTEXT wxRichTextTableBlock
  4578. {
  4579. public:
  4580. wxRichTextTableBlock() { Init(); }
  4581. wxRichTextTableBlock(int colStart, int colEnd, int rowStart, int rowEnd)
  4582. { Init(); m_colStart = colStart; m_colEnd = colEnd; m_rowStart = rowStart; m_rowEnd = rowEnd; }
  4583. wxRichTextTableBlock(const wxRichTextTableBlock& block) { Copy(block); }
  4584. void Init() { m_colStart = 0; m_colEnd = 0; m_rowStart = 0; m_rowEnd = 0; }
  4585. void Copy(const wxRichTextTableBlock& block)
  4586. {
  4587. m_colStart = block.m_colStart; m_colEnd = block.m_colEnd; m_rowStart = block.m_rowStart; m_rowEnd = block.m_rowEnd;
  4588. }
  4589. void operator=(const wxRichTextTableBlock& block) { Copy(block); }
  4590. bool operator==(const wxRichTextTableBlock& block)
  4591. { return m_colStart == block.m_colStart && m_colEnd == block.m_colEnd && m_rowStart == block.m_rowStart && m_rowEnd == block.m_rowEnd; }
  4592. /// Computes the block given a table (perhaps about to be edited) and a rich text control
  4593. /// that may have a selection. If no selection, the whole table is used. If just the whole content
  4594. /// of one cell is selected, this cell only is used. If the cell contents is not selected and
  4595. /// requireCellSelection is @false, the focused cell will count as a selected cell.
  4596. bool ComputeBlockForSelection(wxRichTextTable* table, wxRichTextCtrl* ctrl, bool requireCellSelection = true);
  4597. /// Does this block represent the whole table?
  4598. bool IsWholeTable(wxRichTextTable* table) const;
  4599. /// Returns the cell focused in the table, if any
  4600. static wxRichTextCell* GetFocusedCell(wxRichTextCtrl* ctrl);
  4601. int& ColStart() { return m_colStart; }
  4602. int ColStart() const { return m_colStart; }
  4603. int& ColEnd() { return m_colEnd; }
  4604. int ColEnd() const { return m_colEnd; }
  4605. int& RowStart() { return m_rowStart; }
  4606. int RowStart() const { return m_rowStart; }
  4607. int& RowEnd() { return m_rowEnd; }
  4608. int RowEnd() const { return m_rowEnd; }
  4609. int m_colStart, m_colEnd, m_rowStart, m_rowEnd;
  4610. };
  4611. /**
  4612. The command identifiers for Do/Undo.
  4613. */
  4614. enum wxRichTextCommandId
  4615. {
  4616. wxRICHTEXT_INSERT,
  4617. wxRICHTEXT_DELETE,
  4618. wxRICHTEXT_CHANGE_ATTRIBUTES,
  4619. wxRICHTEXT_CHANGE_STYLE,
  4620. wxRICHTEXT_CHANGE_PROPERTIES,
  4621. wxRICHTEXT_CHANGE_OBJECT
  4622. };
  4623. /**
  4624. @class wxRichTextObjectAddress
  4625. A class for specifying an object anywhere in an object hierarchy,
  4626. without using a pointer, necessary since wxRTC commands may delete
  4627. and recreate sub-objects so physical object addresses change. An array
  4628. of positions (one per hierarchy level) is used.
  4629. @library{wxrichtext}
  4630. @category{richtext}
  4631. @see wxRichTextCommand
  4632. */
  4633. class WXDLLIMPEXP_RICHTEXT wxRichTextObjectAddress
  4634. {
  4635. public:
  4636. /**
  4637. Creates the address given a container and an object.
  4638. */
  4639. wxRichTextObjectAddress(wxRichTextParagraphLayoutBox* topLevelContainer, wxRichTextObject* obj) { Create(topLevelContainer, obj); }
  4640. /**
  4641. */
  4642. wxRichTextObjectAddress() { Init(); }
  4643. /**
  4644. */
  4645. wxRichTextObjectAddress(const wxRichTextObjectAddress& address) { Copy(address); }
  4646. void Init() {}
  4647. /**
  4648. Copies the address.
  4649. */
  4650. void Copy(const wxRichTextObjectAddress& address) { m_address = address.m_address; }
  4651. /**
  4652. Assignment operator.
  4653. */
  4654. void operator=(const wxRichTextObjectAddress& address) { Copy(address); }
  4655. /**
  4656. Returns the object specified by the address, given a top level container.
  4657. */
  4658. wxRichTextObject* GetObject(wxRichTextParagraphLayoutBox* topLevelContainer) const;
  4659. /**
  4660. Creates the address given a container and an object.
  4661. */
  4662. bool Create(wxRichTextParagraphLayoutBox* topLevelContainer, wxRichTextObject* obj);
  4663. /**
  4664. Returns the array of integers representing the object address.
  4665. */
  4666. wxArrayInt& GetAddress() { return m_address; }
  4667. /**
  4668. Returns the array of integers representing the object address.
  4669. */
  4670. const wxArrayInt& GetAddress() const { return m_address; }
  4671. /**
  4672. Sets the address from an array of integers.
  4673. */
  4674. void SetAddress(const wxArrayInt& address) { m_address = address; }
  4675. protected:
  4676. wxArrayInt m_address;
  4677. };
  4678. class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextAction;
  4679. /**
  4680. @class wxRichTextCommand
  4681. Implements a command on the undo/redo stack. A wxRichTextCommand object contains one or more wxRichTextAction
  4682. objects, allowing aggregation of a number of operations into one command.
  4683. @library{wxrichtext}
  4684. @category{richtext}
  4685. @see wxRichTextAction
  4686. */
  4687. class WXDLLIMPEXP_RICHTEXT wxRichTextCommand: public wxCommand
  4688. {
  4689. public:
  4690. /**
  4691. Constructor for one action.
  4692. */
  4693. wxRichTextCommand(const wxString& name, wxRichTextCommandId id, wxRichTextBuffer* buffer,
  4694. wxRichTextParagraphLayoutBox* container, wxRichTextCtrl* ctrl, bool ignoreFirstTime = false);
  4695. /**
  4696. Constructor for multiple actions.
  4697. */
  4698. wxRichTextCommand(const wxString& name);
  4699. virtual ~wxRichTextCommand();
  4700. /**
  4701. Performs the command.
  4702. */
  4703. bool Do();
  4704. /**
  4705. Undoes the command.
  4706. */
  4707. bool Undo();
  4708. /**
  4709. Adds an action to the action list.
  4710. */
  4711. void AddAction(wxRichTextAction* action);
  4712. /**
  4713. Clears the action list.
  4714. */
  4715. void ClearActions();
  4716. /**
  4717. Returns the action list.
  4718. */
  4719. wxList& GetActions() { return m_actions; }
  4720. protected:
  4721. wxList m_actions;
  4722. };
  4723. /**
  4724. @class wxRichTextAction
  4725. Implements a part of a command.
  4726. @library{wxrichtext}
  4727. @category{richtext}
  4728. @see wxRichTextCommand
  4729. */
  4730. class WXDLLIMPEXP_RICHTEXT wxRichTextAction: public wxObject
  4731. {
  4732. public:
  4733. /**
  4734. Constructor. @a buffer is the top-level buffer, while @a container is the object within
  4735. which the action is taking place. In the simplest case, they are the same.
  4736. */
  4737. wxRichTextAction(wxRichTextCommand* cmd, const wxString& name, wxRichTextCommandId id,
  4738. wxRichTextBuffer* buffer, wxRichTextParagraphLayoutBox* container,
  4739. wxRichTextCtrl* ctrl, bool ignoreFirstTime = false);
  4740. virtual ~wxRichTextAction();
  4741. /**
  4742. Performs the action.
  4743. */
  4744. bool Do();
  4745. /**
  4746. Undoes the action.
  4747. */
  4748. bool Undo();
  4749. /**
  4750. Updates the control appearance, optimizing if possible given information from the call to Layout.
  4751. */
  4752. void UpdateAppearance(long caretPosition, bool sendUpdateEvent = false,
  4753. wxArrayInt* optimizationLineCharPositions = NULL, wxArrayInt* optimizationLineYPositions = NULL, bool isDoCmd = true);
  4754. /**
  4755. Replaces the buffer paragraphs with the given fragment.
  4756. */
  4757. void ApplyParagraphs(const wxRichTextParagraphLayoutBox& fragment);
  4758. /**
  4759. Returns the new fragments.
  4760. */
  4761. wxRichTextParagraphLayoutBox& GetNewParagraphs() { return m_newParagraphs; }
  4762. /**
  4763. Returns the old fragments.
  4764. */
  4765. wxRichTextParagraphLayoutBox& GetOldParagraphs() { return m_oldParagraphs; }
  4766. /**
  4767. Returns the attributes, for single-object commands.
  4768. */
  4769. wxRichTextAttr& GetAttributes() { return m_attributes; }
  4770. /**
  4771. Returns the object to replace the one at the position defined by the container address
  4772. and the action's range start position.
  4773. */
  4774. wxRichTextObject* GetObject() const { return m_object; }
  4775. /**
  4776. Stores the object to replace the one at the position defined by the container address
  4777. without making an address for it (cf SetObject() and MakeObject()).
  4778. */
  4779. void StoreObject(wxRichTextObject* obj) { m_object = obj; }
  4780. /**
  4781. Sets the object to replace the one at the position defined by the container address
  4782. and the action's range start position.
  4783. */
  4784. void SetObject(wxRichTextObject* obj) { m_object = obj; m_objectAddress.Create(m_buffer, m_object); }
  4785. /**
  4786. Makes an address from the given object.
  4787. */
  4788. void MakeObject(wxRichTextObject* obj) { m_objectAddress.Create(m_buffer, obj); }
  4789. /**
  4790. Sets the existing and new objects, for use with wxRICHTEXT_CHANGE_OBJECT.
  4791. */
  4792. void SetOldAndNewObjects(wxRichTextObject* oldObj, wxRichTextObject* newObj) { SetObject(oldObj); StoreObject(newObj); }
  4793. /**
  4794. Calculate arrays for refresh optimization.
  4795. */
  4796. void CalculateRefreshOptimizations(wxArrayInt& optimizationLineCharPositions, wxArrayInt& optimizationLineYPositions);
  4797. /**
  4798. Sets the position used for e.g. insertion.
  4799. */
  4800. void SetPosition(long pos) { m_position = pos; }
  4801. /**
  4802. Returns the position used for e.g. insertion.
  4803. */
  4804. long GetPosition() const { return m_position; }
  4805. /**
  4806. Sets the range for e.g. deletion.
  4807. */
  4808. void SetRange(const wxRichTextRange& range) { m_range = range; }
  4809. /**
  4810. Returns the range for e.g. deletion.
  4811. */
  4812. const wxRichTextRange& GetRange() const { return m_range; }
  4813. /**
  4814. Returns the address (nested position) of the container within the buffer being manipulated.
  4815. */
  4816. wxRichTextObjectAddress& GetContainerAddress() { return m_containerAddress; }
  4817. /**
  4818. Returns the address (nested position) of the container within the buffer being manipulated.
  4819. */
  4820. const wxRichTextObjectAddress& GetContainerAddress() const { return m_containerAddress; }
  4821. /**
  4822. Sets the address (nested position) of the container within the buffer being manipulated.
  4823. */
  4824. void SetContainerAddress(const wxRichTextObjectAddress& address) { m_containerAddress = address; }
  4825. /**
  4826. Sets the address (nested position) of the container within the buffer being manipulated.
  4827. */
  4828. void SetContainerAddress(wxRichTextParagraphLayoutBox* container, wxRichTextObject* obj) { m_containerAddress.Create(container, obj); }
  4829. /**
  4830. Returns the container that this action refers to, using the container address and top-level buffer.
  4831. */
  4832. wxRichTextParagraphLayoutBox* GetContainer() const;
  4833. /**
  4834. Returns the action name.
  4835. */
  4836. const wxString& GetName() const { return m_name; }
  4837. /**
  4838. Instructs the first Do() command should be skipped as it's already been applied.
  4839. */
  4840. void SetIgnoreFirstTime(bool b) { m_ignoreThis = b; }
  4841. /**
  4842. Returns true if the first Do() command should be skipped as it's already been applied.
  4843. */
  4844. bool GetIgnoreFirstTime() const { return m_ignoreThis; }
  4845. protected:
  4846. // Action name
  4847. wxString m_name;
  4848. // Buffer
  4849. wxRichTextBuffer* m_buffer;
  4850. // The address (nested position) of the container being manipulated.
  4851. // This is necessary because objects are deleted, and we can't
  4852. // therefore store actual pointers.
  4853. wxRichTextObjectAddress m_containerAddress;
  4854. // Control
  4855. wxRichTextCtrl* m_ctrl;
  4856. // Stores the new paragraphs
  4857. wxRichTextParagraphLayoutBox m_newParagraphs;
  4858. // Stores the old paragraphs
  4859. wxRichTextParagraphLayoutBox m_oldParagraphs;
  4860. // Stores an object to replace the one at the position
  4861. // defined by the container address and the action's range start position.
  4862. wxRichTextObject* m_object;
  4863. // Stores the attributes
  4864. wxRichTextAttr m_attributes;
  4865. // The address of the object being manipulated (used for changing an individual object or its attributes)
  4866. wxRichTextObjectAddress m_objectAddress;
  4867. // Stores the old attributes
  4868. // wxRichTextAttr m_oldAttributes;
  4869. // The affected range
  4870. wxRichTextRange m_range;
  4871. // The insertion point for this command
  4872. long m_position;
  4873. // Ignore 1st 'Do' operation because we already did it
  4874. bool m_ignoreThis;
  4875. // The command identifier
  4876. wxRichTextCommandId m_cmdId;
  4877. };
  4878. /*!
  4879. * Handler flags
  4880. */
  4881. // Include style sheet when loading and saving
  4882. #define wxRICHTEXT_HANDLER_INCLUDE_STYLESHEET 0x0001
  4883. // Save images to memory file system in HTML handler
  4884. #define wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_MEMORY 0x0010
  4885. // Save images to files in HTML handler
  4886. #define wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_FILES 0x0020
  4887. // Save images as inline base64 data in HTML handler
  4888. #define wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_BASE64 0x0040
  4889. // Don't write header and footer (or BODY), so we can include the fragment
  4890. // in a larger document
  4891. #define wxRICHTEXT_HANDLER_NO_HEADER_FOOTER 0x0080
  4892. // Convert the more common face names to names that will work on the current platform
  4893. // in a larger document
  4894. #define wxRICHTEXT_HANDLER_CONVERT_FACENAMES 0x0100
  4895. /**
  4896. @class wxRichTextFileHandler
  4897. The base class for file handlers.
  4898. @library{wxrichtext}
  4899. @category{richtext}
  4900. @see wxRichTextBuffer, wxRichTextCtrl
  4901. */
  4902. class WXDLLIMPEXP_RICHTEXT wxRichTextFileHandler: public wxObject
  4903. {
  4904. DECLARE_CLASS(wxRichTextFileHandler)
  4905. public:
  4906. /**
  4907. Creates a file handler object.
  4908. */
  4909. wxRichTextFileHandler(const wxString& name = wxEmptyString, const wxString& ext = wxEmptyString, int type = 0)
  4910. : m_name(name), m_extension(ext), m_type(type), m_flags(0), m_visible(true)
  4911. { }
  4912. #if wxUSE_STREAMS
  4913. /**
  4914. Loads the buffer from a stream.
  4915. Not all handlers will implement file loading.
  4916. */
  4917. bool LoadFile(wxRichTextBuffer *buffer, wxInputStream& stream)
  4918. { return DoLoadFile(buffer, stream); }
  4919. /**
  4920. Saves the buffer to a stream.
  4921. Not all handlers will implement file saving.
  4922. */
  4923. bool SaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream)
  4924. { return DoSaveFile(buffer, stream); }
  4925. #endif
  4926. #if wxUSE_FFILE && wxUSE_STREAMS
  4927. /**
  4928. Loads the buffer from a file.
  4929. */
  4930. virtual bool LoadFile(wxRichTextBuffer *buffer, const wxString& filename);
  4931. /**
  4932. Saves the buffer to a file.
  4933. */
  4934. virtual bool SaveFile(wxRichTextBuffer *buffer, const wxString& filename);
  4935. #endif // wxUSE_STREAMS && wxUSE_STREAMS
  4936. /**
  4937. Returns @true if we handle this filename (if using files). By default, checks the extension.
  4938. */
  4939. virtual bool CanHandle(const wxString& filename) const;
  4940. /**
  4941. Returns @true if we can save using this handler.
  4942. */
  4943. virtual bool CanSave() const { return false; }
  4944. /**
  4945. Returns @true if we can load using this handler.
  4946. */
  4947. virtual bool CanLoad() const { return false; }
  4948. /**
  4949. Returns @true if this handler should be visible to the user.
  4950. */
  4951. virtual bool IsVisible() const { return m_visible; }
  4952. /**
  4953. Sets whether the handler should be visible to the user (via the application's
  4954. load and save dialogs).
  4955. */
  4956. virtual void SetVisible(bool visible) { m_visible = visible; }
  4957. /**
  4958. Sets the name of the handler.
  4959. */
  4960. void SetName(const wxString& name) { m_name = name; }
  4961. /**
  4962. Returns the name of the handler.
  4963. */
  4964. wxString GetName() const { return m_name; }
  4965. /**
  4966. Sets the default extension to recognise.
  4967. */
  4968. void SetExtension(const wxString& ext) { m_extension = ext; }
  4969. /**
  4970. Returns the default extension to recognise.
  4971. */
  4972. wxString GetExtension() const { return m_extension; }
  4973. /**
  4974. Sets the handler type.
  4975. */
  4976. void SetType(int type) { m_type = type; }
  4977. /**
  4978. Returns the handler type.
  4979. */
  4980. int GetType() const { return m_type; }
  4981. /**
  4982. Sets flags that change the behaviour of loading or saving.
  4983. See the documentation for each handler class to see what flags are relevant
  4984. for each handler.
  4985. You call this function directly if you are using a file handler explicitly
  4986. (without going through the text control or buffer LoadFile/SaveFile API).
  4987. Or, you can call the control or buffer's SetHandlerFlags function to set
  4988. the flags that will be used for subsequent load and save operations.
  4989. */
  4990. void SetFlags(int flags) { m_flags = flags; }
  4991. /**
  4992. Returns flags controlling how loading and saving is done.
  4993. */
  4994. int GetFlags() const { return m_flags; }
  4995. /**
  4996. Sets the encoding to use when saving a file. If empty, a suitable encoding is chosen.
  4997. */
  4998. void SetEncoding(const wxString& encoding) { m_encoding = encoding; }
  4999. /**
  5000. Returns the encoding to use when saving a file. If empty, a suitable encoding is chosen.
  5001. */
  5002. const wxString& GetEncoding() const { return m_encoding; }
  5003. protected:
  5004. #if wxUSE_STREAMS
  5005. /**
  5006. Override to load content from @a stream into @a buffer.
  5007. */
  5008. virtual bool DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream) = 0;
  5009. /**
  5010. Override to save content to @a stream from @a buffer.
  5011. */
  5012. virtual bool DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream) = 0;
  5013. #endif
  5014. wxString m_name;
  5015. wxString m_encoding;
  5016. wxString m_extension;
  5017. int m_type;
  5018. int m_flags;
  5019. bool m_visible;
  5020. };
  5021. /**
  5022. @class wxRichTextPlainTextHandler
  5023. Implements saving a buffer to plain text.
  5024. @library{wxrichtext}
  5025. @category{richtext}
  5026. @see wxRichTextFileHandler, wxRichTextBuffer, wxRichTextCtrl
  5027. */
  5028. class WXDLLIMPEXP_RICHTEXT wxRichTextPlainTextHandler: public wxRichTextFileHandler
  5029. {
  5030. DECLARE_CLASS(wxRichTextPlainTextHandler)
  5031. public:
  5032. wxRichTextPlainTextHandler(const wxString& name = wxT("Text"),
  5033. const wxString& ext = wxT("txt"),
  5034. wxRichTextFileType type = wxRICHTEXT_TYPE_TEXT)
  5035. : wxRichTextFileHandler(name, ext, type)
  5036. { }
  5037. // Can we save using this handler?
  5038. virtual bool CanSave() const { return true; }
  5039. // Can we load using this handler?
  5040. virtual bool CanLoad() const { return true; }
  5041. protected:
  5042. #if wxUSE_STREAMS
  5043. virtual bool DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream);
  5044. virtual bool DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream);
  5045. #endif
  5046. };
  5047. /**
  5048. @class wxRichTextDrawingHandler
  5049. The base class for custom drawing handlers.
  5050. Currently, drawing handlers can provide virtual attributes.
  5051. @library{wxrichtext}
  5052. @category{richtext}
  5053. @see wxRichTextBuffer, wxRichTextCtrl
  5054. */
  5055. class WXDLLIMPEXP_RICHTEXT wxRichTextDrawingHandler: public wxObject
  5056. {
  5057. DECLARE_CLASS(wxRichTextDrawingHandler)
  5058. public:
  5059. /**
  5060. Creates a drawing handler object.
  5061. */
  5062. wxRichTextDrawingHandler(const wxString& name = wxEmptyString)
  5063. : m_name(name)
  5064. { }
  5065. /**
  5066. Returns @true if this object has virtual attributes that we can provide.
  5067. */
  5068. virtual bool HasVirtualAttributes(wxRichTextObject* obj) const = 0;
  5069. /**
  5070. Provides virtual attributes that we can provide.
  5071. */
  5072. virtual bool GetVirtualAttributes(wxRichTextAttr& attr, wxRichTextObject* obj) const = 0;
  5073. /**
  5074. Gets the count for mixed virtual attributes for individual positions within the object.
  5075. For example, individual characters within a text object may require special highlighting.
  5076. */
  5077. virtual int GetVirtualSubobjectAttributesCount(wxRichTextObject* obj) const = 0;
  5078. /**
  5079. Gets the mixed virtual attributes for individual positions within the object.
  5080. For example, individual characters within a text object may require special highlighting.
  5081. Returns the number of virtual attributes found.
  5082. */
  5083. virtual int GetVirtualSubobjectAttributes(wxRichTextObject* obj, wxArrayInt& positions, wxRichTextAttrArray& attributes) const = 0;
  5084. /**
  5085. Do we have virtual text for this object? Virtual text allows an application
  5086. to replace characters in an object for editing and display purposes, for example
  5087. for highlighting special characters.
  5088. */
  5089. virtual bool HasVirtualText(const wxRichTextPlainText* obj) const = 0;
  5090. /**
  5091. Gets the virtual text for this object.
  5092. */
  5093. virtual bool GetVirtualText(const wxRichTextPlainText* obj, wxString& text) const = 0;
  5094. /**
  5095. Sets the name of the handler.
  5096. */
  5097. void SetName(const wxString& name) { m_name = name; }
  5098. /**
  5099. Returns the name of the handler.
  5100. */
  5101. wxString GetName() const { return m_name; }
  5102. protected:
  5103. wxString m_name;
  5104. };
  5105. #if wxUSE_DATAOBJ
  5106. /**
  5107. @class wxRichTextBufferDataObject
  5108. Implements a rich text data object for clipboard transfer.
  5109. @library{wxrichtext}
  5110. @category{richtext}
  5111. @see wxDataObjectSimple, wxRichTextBuffer, wxRichTextCtrl
  5112. */
  5113. class WXDLLIMPEXP_RICHTEXT wxRichTextBufferDataObject: public wxDataObjectSimple
  5114. {
  5115. public:
  5116. /**
  5117. The constructor doesn't copy the pointer, so it shouldn't go away while this object
  5118. is alive.
  5119. */
  5120. wxRichTextBufferDataObject(wxRichTextBuffer* richTextBuffer = NULL);
  5121. virtual ~wxRichTextBufferDataObject();
  5122. /**
  5123. After a call to this function, the buffer is owned by the caller and it
  5124. is responsible for deleting it.
  5125. */
  5126. wxRichTextBuffer* GetRichTextBuffer();
  5127. /**
  5128. Returns the id for the new data format.
  5129. */
  5130. static const wxChar* GetRichTextBufferFormatId() { return ms_richTextBufferFormatId; }
  5131. // base class pure virtuals
  5132. virtual wxDataFormat GetPreferredFormat(Direction dir) const;
  5133. virtual size_t GetDataSize() const;
  5134. virtual bool GetDataHere(void *pBuf) const;
  5135. virtual bool SetData(size_t len, const void *buf);
  5136. // prevent warnings
  5137. virtual size_t GetDataSize(const wxDataFormat&) const { return GetDataSize(); }
  5138. virtual bool GetDataHere(const wxDataFormat&, void *buf) const { return GetDataHere(buf); }
  5139. virtual bool SetData(const wxDataFormat&, size_t len, const void *buf) { return SetData(len, buf); }
  5140. private:
  5141. wxDataFormat m_formatRichTextBuffer; // our custom format
  5142. wxRichTextBuffer* m_richTextBuffer; // our data
  5143. static const wxChar* ms_richTextBufferFormatId; // our format id
  5144. };
  5145. #endif
  5146. /**
  5147. @class wxRichTextRenderer
  5148. This class isolates some common drawing functionality.
  5149. @library{wxrichtext}
  5150. @category{richtext}
  5151. @see wxRichTextBuffer, wxRichTextCtrl
  5152. */
  5153. class WXDLLIMPEXP_RICHTEXT wxRichTextRenderer: public wxObject
  5154. {
  5155. public:
  5156. /**
  5157. Constructor.
  5158. */
  5159. wxRichTextRenderer() {}
  5160. virtual ~wxRichTextRenderer() {}
  5161. /**
  5162. Draws a standard bullet, as specified by the value of GetBulletName. This function should be overridden.
  5163. */
  5164. virtual bool DrawStandardBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxRichTextAttr& attr, const wxRect& rect) = 0;
  5165. /**
  5166. Draws a bullet that can be described by text, such as numbered or symbol bullets. This function should be overridden.
  5167. */
  5168. virtual bool DrawTextBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxRichTextAttr& attr, const wxRect& rect, const wxString& text) = 0;
  5169. /**
  5170. Draws a bitmap bullet, where the bullet bitmap is specified by the value of GetBulletName. This function should be overridden.
  5171. */
  5172. virtual bool DrawBitmapBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxRichTextAttr& attr, const wxRect& rect) = 0;
  5173. /**
  5174. Enumerate the standard bullet names currently supported. This function should be overridden.
  5175. */
  5176. virtual bool EnumerateStandardBulletNames(wxArrayString& bulletNames) = 0;
  5177. };
  5178. /**
  5179. @class wxRichTextStdRenderer
  5180. The standard renderer for drawing bullets.
  5181. @library{wxrichtext}
  5182. @category{richtext}
  5183. @see wxRichTextRenderer, wxRichTextBuffer, wxRichTextCtrl
  5184. */
  5185. class WXDLLIMPEXP_RICHTEXT wxRichTextStdRenderer: public wxRichTextRenderer
  5186. {
  5187. public:
  5188. /**
  5189. Constructor.
  5190. */
  5191. wxRichTextStdRenderer() {}
  5192. // Draw a standard bullet, as specified by the value of GetBulletName
  5193. virtual bool DrawStandardBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxRichTextAttr& attr, const wxRect& rect);
  5194. // Draw a bullet that can be described by text, such as numbered or symbol bullets
  5195. virtual bool DrawTextBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxRichTextAttr& attr, const wxRect& rect, const wxString& text);
  5196. // Draw a bitmap bullet, where the bullet bitmap is specified by the value of GetBulletName
  5197. virtual bool DrawBitmapBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxRichTextAttr& attr, const wxRect& rect);
  5198. // Enumerate the standard bullet names currently supported
  5199. virtual bool EnumerateStandardBulletNames(wxArrayString& bulletNames);
  5200. };
  5201. /*!
  5202. * Utilities
  5203. *
  5204. */
  5205. inline bool wxRichTextHasStyle(int flags, int style)
  5206. {
  5207. return ((flags & style) == style);
  5208. }
  5209. /// Compare two attribute objects
  5210. WXDLLIMPEXP_RICHTEXT bool wxTextAttrEq(const wxRichTextAttr& attr1, const wxRichTextAttr& attr2);
  5211. WXDLLIMPEXP_RICHTEXT bool wxTextAttrEq(const wxRichTextAttr& attr1, const wxRichTextAttr& attr2);
  5212. /// Apply one style to another
  5213. WXDLLIMPEXP_RICHTEXT bool wxRichTextApplyStyle(wxRichTextAttr& destStyle, const wxRichTextAttr& style, wxRichTextAttr* compareWith = NULL);
  5214. // Remove attributes
  5215. WXDLLIMPEXP_RICHTEXT bool wxRichTextRemoveStyle(wxRichTextAttr& destStyle, const wxRichTextAttr& style);
  5216. /// Combine two bitlists
  5217. WXDLLIMPEXP_RICHTEXT bool wxRichTextCombineBitlists(int& valueA, int valueB, int& flagsA, int flagsB);
  5218. /// Compare two bitlists
  5219. WXDLLIMPEXP_RICHTEXT bool wxRichTextBitlistsEqPartial(int valueA, int valueB, int flags);
  5220. /// Split into paragraph and character styles
  5221. WXDLLIMPEXP_RICHTEXT bool wxRichTextSplitParaCharStyles(const wxRichTextAttr& style, wxRichTextAttr& parStyle, wxRichTextAttr& charStyle);
  5222. /// Compare tabs
  5223. WXDLLIMPEXP_RICHTEXT bool wxRichTextTabsEq(const wxArrayInt& tabs1, const wxArrayInt& tabs2);
  5224. /// Convert a decimal to Roman numerals
  5225. WXDLLIMPEXP_RICHTEXT wxString wxRichTextDecimalToRoman(long n);
  5226. // Collects the attributes that are common to a range of content, building up a note of
  5227. // which attributes are absent in some objects and which clash in some objects.
  5228. WXDLLIMPEXP_RICHTEXT void wxTextAttrCollectCommonAttributes(wxTextAttr& currentStyle, const wxTextAttr& attr, wxTextAttr& clashingAttr, wxTextAttr& absentAttr);
  5229. WXDLLIMPEXP_RICHTEXT void wxRichTextModuleInit();
  5230. #endif
  5231. // wxUSE_RICHTEXT
  5232. #endif
  5233. // _WX_RICHTEXTBUFFER_H_