2
0

win32maxguiex.bmx 143 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056
  1. Rem
  2. bbdoc: MaxGUI Drivers/Win32MaxGUIEx
  3. End Rem
  4. Module MaxGUI.Win32MaxGUIEx
  5. ModuleInfo "Version: 0.75"
  6. ModuleInfo "Author: Simon Armstrong, Seb Hollington"
  7. ModuleInfo "License: zlib/libpng"
  8. Strict
  9. ?Win32
  10. Import MaxGUI.MaxGUI
  11. Import "winimports.bmx"
  12. maxgui_driver = New TWindowsGUIDriver
  13. Type TWindowsGUIDriver Extends TMaxGUIDriver
  14. Global GadgetMap:TMap
  15. Global GDIDesktop:TWindowsDesktop
  16. Global GDIFont:TWindowsFont
  17. Global ClassAtom
  18. Global ClassAtom2
  19. Global KBMessageHook,MouseMessageHook
  20. Global windowtheme:Short Ptr
  21. Global _cursor, _commoncontrolversion[]
  22. Global _explorerstyle = False
  23. Global _activeWindow:TWindowsWindow = Null
  24. Global _customcolors[] = [$FFFFFF, $FFFFFF, $FFFFFF, $FFFFFF, $FFFFFF, $FFFFFF, $FFFFFF, $FFFFFF, ..
  25. $FFFFFF, $FFFFFF, $FFFFFF, $FFFFFF, $FFFFFF, $FFFFFF, $FFFFFF, $FFFFFF ]
  26. Global _hwndTooltips%
  27. Global intDontReleaseCapture% = False 'See WM_CAPTURECHANGED
  28. Method New()
  29. 'Initialize libraries
  30. OleInitialize(Null)
  31. Local icc:TINITCOMMONCONTROLSEX = New TINITCOMMONCONTROLSEX
  32. icc.dwSize = SizeOf(icc)
  33. icc.dwICC = ICC_WIN95_CLASSES|ICC_USEREX_CLASSES'|ICC_COOL_CLASSES'|ICC_DATE_CLASSES
  34. InitCommonControlsEx icc
  35. 'Initialize Global Variables
  36. GDIFont=TWindowsFont.DefaultFont()
  37. GadgetMap=New TMap
  38. GDIDesktop=New TWindowsDesktop
  39. 'Set-up Message Hooks
  40. KBMessageHook=SetWindowsHookExW(WH_KEYBOARD,KeyboardProc,GetModuleHandleW(Null),GetCurrentThreadId())
  41. MouseMessageHook=SetWindowsHookExW(WH_MOUSE,MouseProc,GetModuleHandleW(Null),GetCurrentThreadId())
  42. 'Gadget Tooltips
  43. _hwndTooltips = CreateWindowExW( 0,"tooltips_class32","",WS_POPUP|TTS_ALWAYSTIP,0,0,0,0,GDIDesktop._hwnd,0,GetModuleHandleW(Null),Null )
  44. SendMessageW( _hwndTooltips, TTM_SETMAXTIPWIDTH, 0, 300 )
  45. SetWindowPos( _hwndTooltips, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE )
  46. EndMethod
  47. Method Delete()
  48. DestroyWindow( _hwndTooltips );_hwndTooltips = 0
  49. UnhookWindowsHookEx MouseMessageHook
  50. UnhookWindowsHookEx KBMessageHook
  51. EndMethod
  52. Method UserName$()
  53. Return getenv_("username")
  54. End Method
  55. Method ComputerName$()
  56. Return getenv_("userdomain")
  57. End Method
  58. 'Low-level Win32 interface
  59. Function RegisterHwnd(hwnd,gadget:TWindowsGadget)
  60. GadgetMap.Insert TIntWrapper.Create(hwnd),gadget
  61. EndFunction
  62. Function RemoveHwnd(hwnd)
  63. GadgetMap.Remove TIntWrapper.Create(hwnd)
  64. EndFunction
  65. Function GadgetFromHwnd:TWindowsGadget(hwnd) nodebug
  66. Return TWindowsGadget(GadgetMap.ValueForKey(TIntWrapper.Create(hwnd)))
  67. EndFunction
  68. Function ClassWndProc(hwnd,msg,wp,lp) "win32"
  69. Local owner:TWindowsGadget
  70. Local res
  71. Local nmhdr:Int Ptr
  72. '?Debug And Win32
  73. 'Print TWindowsDebug.ReverseLookupMsg(msg) + ", hwnd: " + hwnd + ", wp: " + wp + ", lp: " + lp
  74. '?Win32
  75. Select msg
  76. Case WM_MENUCHAR
  77. If HotKeyEventFromWp(wp & $FF) Then
  78. Return (MNC_CLOSE Shl 16)
  79. Else
  80. Return (MNC_IGNORE Shl 16)
  81. EndIf
  82. Case WM_SIZE
  83. owner = GadgetFromHwnd(hwnd)
  84. If owner And Not TWindowsWindow(owner) Then
  85. If hwnd = owner.Query(QUERY_HWND) Then owner.RethinkClient()
  86. If hwnd = owner.Query(QUERY_HWND_CLIENT) Then owner.LayoutKids()
  87. EndIf
  88. Case WM_CTLCOLORSTATIC, WM_CTLCOLOREDIT, WM_CTLCOLORBTN
  89. owner=GadgetFromHwnd(lp)
  90. Select True
  91. Case TWindowsLabel(owner) <> Null
  92. SetBkMode(wp, TRANSPARENT)
  93. If owner.FgColor() > -1 Then SetTextColor_(wp, owner.FgColor())
  94. Return owner.CreateControlBrush( owner._hwnd, wp )
  95. Case TWindowsPanel(owner) <> Null
  96. If TWindowsPanel(owner)._type = TWindowsPanel.PANELGROUP Then
  97. SetBkMode(wp, TRANSPARENT)
  98. If owner.FgColor() > -1 Then SetTextColor_(wp, owner.FgColor())
  99. Return owner.CreateControlBrush( lp, wp )
  100. EndIf
  101. Case TWindowsTextField(owner) <> Null, TWindowsComboBox(owner) <> Null
  102. If owner.FgColor() > -1 Then SetTextColor_(wp, owner.FgColor())
  103. If owner.BgBrush() Then SetBkColor(wp, owner.BgColor());Return owner.BgBrush()
  104. Case TWindowsButton(owner) <> Null, TWindowsSlider(owner) <> Null
  105. SetBkMode(wp, TRANSPARENT)
  106. If owner.FgColor() > -1 Then SetTextColor_(wp, owner.FgColor())
  107. Return owner.CreateControlBrush( owner._hwnd, wp )
  108. EndSelect
  109. owner = Null
  110. Case WM_COMMAND,WM_HSCROLL,WM_VSCROLL
  111. If lp Then
  112. owner=GadgetFromHwnd(lp)
  113. 'Fix for tab control's up/down arrow.
  114. If Not owner Then owner = GadgetFromHwnd(GetParent_(lp))
  115. Else
  116. owner=GadgetFromHwnd(hwnd) 'Fixed for menu events
  117. EndIf
  118. If Not owner Then owner = GadgetFromHwnd(hwnd)
  119. If owner Then
  120. res=owner.OnCommand(msg,wp)
  121. If Not res And owner._proc And owner._hwnd = hwnd Return CallWindowProcW(owner._proc,hwnd,msg,wp,lp)
  122. Return res
  123. Else
  124. Return DefWindowProcW( hwnd,msg,wp,lp )
  125. EndIf
  126. Case WM_NOTIFY
  127. 'Gadget tooltips
  128. nmhdr=Int Ptr(lp)
  129. owner=GadgetFromHwnd(nmhdr[0])
  130. If owner Then
  131. Select nmhdr[2]
  132. Case TTN_GETDISPINFOW
  133. If owner._wstrTooltip Then nmhdr[3] = Int(owner._wstrTooltip)
  134. EndSelect
  135. Return owner.OnNotify(wp,lp)
  136. EndIf
  137. Case WM_SETCURSOR
  138. If _cursor Then
  139. SetCursor(_cursor)
  140. Return 1
  141. EndIf
  142. Case WM_ACTIVATEAPP, WM_ACTIVATE
  143. SystemEmitOSEvent(hwnd,msg,wp,lp,Null)
  144. Case WM_DPICHANGED
  145. Local g_dpi = wp Shr 16
  146. ' UpdateDpiDependentFontsAndResources();
  147. DebugLog "DPICHANGED to "+g_dpi
  148. Case WM_DRAWITEM
  149. Local tmpDrawItemStruct:DRAWITEMSTRUCT = New DRAWITEMSTRUCT
  150. MemCopy tmpDrawItemStruct, Byte Ptr lp, SizeOf(tmpDrawItemStruct)
  151. owner = GadgetFromHwnd(tmpDrawItemStruct.hwndItem)
  152. If owner And owner.OnDrawItem( tmpDrawItemStruct ) Then Return True
  153. owner = Null
  154. 'Allow BRL.System to handle mouse/key events on sensitive gadgets.
  155. Case WM_CAPTURECHANGED
  156. 'For preventing problem where controls which called SetCapture() internally
  157. 'had their capture prematurely released by the ReleaseCapture() call in BRL.System.
  158. intDontReleaseCapture = False
  159. 'If SetCapture() is called again after BRL.System's call (when the new
  160. 'capture hwnd [lp] = old hwnd [hwnd]) then we dont want to call ReleaseCapture() in BRL.System
  161. 'when WM_MOUSEBUTTONUP is received by the system hook TWindowsGUIDriver.MouseProc().
  162. If (lp = hwnd) And (Not intEmitOSEvent) Then intDontReleaseCapture = True
  163. Default
  164. 'Added preliminary check to avoid searching for a gadget in GadgetMap un-necessarily.
  165. If (msg = WM_MOUSEWHEEL) Or (msg = WM_MOUSELEAVE) Or (msg>=WM_KEYFIRST And msg<=WM_KEYLAST) Then
  166. owner=GadgetFromHwnd(hwnd)
  167. If owner Then
  168. Select msg
  169. Case WM_MOUSELEAVE, WM_MOUSEWHEEL
  170. If (owner.sensitivity&SENSITIZE_MOUSE) Then SystemEmitOSEvent hwnd,msg,wp,lp,owner
  171. Case WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, WM_SYSKEYUP, WM_CHAR, WM_SYSCHAR
  172. If (owner.sensitivity&SENSITIZE_KEYS) And Not GadgetDisabled(owner) Then
  173. SystemEmitOSEvent hwnd,msg,wp,lp,owner
  174. EndIf
  175. If (msg<>WM_CHAR And msg<>WM_SYSCHAR) And HotKeyEventFromWp(wp) Then Return 1
  176. EndSelect
  177. EndIf
  178. EndIf
  179. EndSelect
  180. If Not owner Then owner=GadgetFromHwnd(hwnd)
  181. If owner Return owner.WndProc(hwnd,msg,wp,lp)
  182. Return DefWindowProcW( hwnd,msg,wp,lp )
  183. EndFunction
  184. Function KeyboardProc( code,wparam,lparam ) "win32" nodebug
  185. Local ev:TEvent, hwnd%, tmpClassName:Short[16], mods:Int, key:Int = wparam
  186. If code>=0 Then
  187. 'Removed: http://www.blitzbasic.com/Community/posts.php?topic=72737
  188. ' Rem
  189. If wparam = $D Then '$D: VK_RETURN
  190. hwnd = GetFocus()
  191. If hwnd And GetClassNameW(hwnd,tmpClassName,tmpClassName.length) And String.FromWString(tmpClassName).ToUpper() = "EDIT" Then
  192. SetFocus(GetParent_(hwnd))
  193. EndIf
  194. EndIf
  195. ' EndRem
  196. ev = HotkeyEventFromWp(wparam)
  197. If ev
  198. 'Hot-key events shouldn't be emitted if the source gadget is disabled
  199. If Not(TGadget(ev.source) And GadgetDisabled(TGadget(ev.source))) Then
  200. If Not (lparam & $80000000) Then
  201. EmitEvent ev
  202. If ev.mods Then Return 1 'Key press events never reach active panels etc. if we return 1
  203. EndIf
  204. EndIf
  205. EndIf
  206. EndIf
  207. Return CallNextHookEx( KBMessageHook,code,wparam,lparam );
  208. EndFunction
  209. Function HotkeyEventFromWp:TEvent(wparam)
  210. Local key = wparam, mods = KeyMods()
  211. Select wparam
  212. Case VK_SHIFT, $A0, $A1
  213. If (wparam=VK_SHIFT) Then key = KEY_LSHIFT
  214. mods:&~MODIFIER_SHIFT
  215. Case VK_CONTROL, $A2, $A3
  216. If (wparam=VK_CONTROL) Then key = KEY_LCONTROL
  217. mods:&~MODIFIER_CONTROL
  218. Case VK_MENU, $A4, $A5
  219. If (wparam=VK_MENU) Then key = KEY_LALT
  220. mods:&~MODIFIER_ALT
  221. Case VK_LWIN, VK_RWIN
  222. mods:&~MODIFIER_SYSTEM
  223. EndSelect
  224. Return HotKeyEvent( key,mods,GetForegroundWindow() )
  225. EndFunction
  226. Global intButtonStates%[3]
  227. Function MouseProc( code,wparam,lparam ) "win32" nodebug
  228. If code>=0 And wparam >= WM_MOUSEFIRST And wparam <= WM_MOUSELAST Then 'Not needed as MouseProc only receives mouse messages!!!
  229. Local MOUSEHOOKSTRUCT:Int Ptr = Int Ptr(lparam), wp, lp, data
  230. Local hwnd% = MOUSEHOOKSTRUCT[2], msg% = wparam, owner:TWindowsGadget
  231. Local point:Int[] = [MOUSEHOOKSTRUCT[0],MOUSEHOOKSTRUCT[1]]
  232. Select msg
  233. Case WM_LBUTTONDOWN, WM_LBUTTONDBLCLK
  234. data = MOUSE_LEFT
  235. msg = WM_LBUTTONDOWN
  236. intButtonStates[MOUSE_LEFT] = True
  237. Case WM_LBUTTONUP
  238. data = MOUSE_LEFT
  239. intButtonStates[MOUSE_LEFT] = False
  240. Case WM_RBUTTONDOWN, WM_RBUTTONDBLCLK
  241. data = MOUSE_RIGHT
  242. msg = WM_RBUTTONDOWN
  243. intButtonStates[MOUSE_RIGHT] = True
  244. Case WM_RBUTTONUP
  245. data = MOUSE_RIGHT
  246. intButtonStates[MOUSE_RIGHT] = False
  247. Case WM_MBUTTONDOWN, WM_MBUTTONDBLCLK
  248. data = MOUSE_MIDDLE
  249. msg = WM_MBUTTONDOWN
  250. intButtonStates[MOUSE_MIDDLE] = True
  251. Case WM_MBUTTONUP
  252. data = MOUSE_MIDDLE
  253. intButtonStates[MOUSE_MIDDLE] = False
  254. EndSelect
  255. owner = GadgetFromHwnd(hwnd)
  256. If owner And ScreenToClient( hwnd, point ) Then
  257. If data And (Not intButtonStates[data]) And TGadget.dragGadget[data-1] Then
  258. PostGuiEvent EVENT_GADGETDROP, owner, data, KeyMods(), point[0], point[1], TGadget.dragGadget[data-1]
  259. TGadget.dragGadget[data-1] = Null
  260. EndIf
  261. If (owner.sensitivity&SENSITIZE_MOUSE) Then
  262. 'Fake wp parameter to pass onto bbSystemEmitOSEvent
  263. If intButtonStates[MOUSE_LEFT] Then wp:|MK_LBUTTON
  264. If intButtonStates[MOUSE_MIDDLE] Then wp:|MK_MBUTTON
  265. If intButtonStates[MOUSE_RIGHT] Then wp:|MK_RBUTTON
  266. If GetKeyState(VK_SHIFT)&$8000 Then wp:|MK_SHIFT
  267. If GetKeyState(VK_CONTROL)&$8000 Then wp:|MK_CONTROL
  268. lp = (Short(point[1]) Shl 16) | Short(point[0])
  269. 'Sort and determine whether to emit the event
  270. Select msg
  271. Case WM_MOUSEMOVE
  272. If (owner._oldcursorlp<>lp) Then
  273. owner._oldcursorlp=lp
  274. SystemEmitOSEvent hwnd,msg,wp,lp,owner
  275. EndIf
  276. Case WM_LBUTTONUP, WM_RBUTTONUP, WM_MBUTTONUP
  277. If intDontReleaseCapture Then
  278. PostGuiEvent EVENT_MOUSEUP, owner, data
  279. Else
  280. SystemEmitOSEvent hwnd,msg,wp,lp,owner
  281. EndIf
  282. Case WM_LBUTTONDOWN, WM_RBUTTONDOWN, WM_MBUTTONDOWN
  283. SystemEmitOSEvent hwnd,msg,wp,lp,owner
  284. EndSelect
  285. EndIf
  286. EndIf
  287. EndIf
  288. Return CallNextHookEx( MouseMessageHook,code,wparam,lparam )
  289. EndFunction
  290. Global intEmitOSEvent
  291. Function SystemEmitOSEvent( hwnd, msg, wp, lp, owner:TGadget )
  292. intEmitOSEvent:+1
  293. If owner Then
  294. While owner.source
  295. owner = owner.source
  296. Wend
  297. EndIf
  298. Local tmpResult% = bbSystemEmitOSEvent( hwnd, msg, wp, lp, owner )
  299. intEmitOSEvent:-1
  300. Return tmpResult
  301. EndFunction
  302. Function ClassName$()
  303. Global _name$
  304. Global _wc:WNDCLASSW
  305. Global _icon
  306. If Not _name
  307. _name="BLITZMAX_WINDOW_CLASS"
  308. _icon=LoadIconW(GetModuleHandleW(Null),Short Ptr(101))
  309. _wc=New WNDCLASSW
  310. _wc.style=CS_OWNDC|CS_HREDRAW|CS_VREDRAW
  311. _wc.lpfnWndProc=ClassWndProc
  312. _wc.hInstance=GetModuleHandleW(Null)
  313. _wc.hIcon=_icon
  314. _wc.hCursor=LoadCursorW( 0,Short Ptr( IDC_ARROW ) )
  315. _wc.hbrBackground=COLOR_BTNSHADOW
  316. _wc.lpszMenuName=Null
  317. _wc.lpszClassName=_name.ToWString()
  318. _wc.cbWndExtra=DLGWINDOWEXTRA
  319. ClassAtom=RegisterClassW(_wc)
  320. EndIf
  321. Return _name
  322. EndFunction
  323. Function DialogClassName$()
  324. Global _dname$
  325. Global _dc:WNDCLASSW
  326. If Not _dname
  327. _dname="BLITZMAX_DIALOG_CLASS"
  328. _dc=New WNDCLASSW
  329. _dc.style=CS_OWNDC|CS_HREDRAW|CS_VREDRAW
  330. _dc.lpfnWndProc=ClassWndProc
  331. _dc.hInstance=GetModuleHandleW(Null)
  332. _dc.hCursor=LoadCursorW( 0,Short Ptr( IDC_ARROW ) )
  333. _dc.hbrBackground=COLOR_BTNSHADOW
  334. _dc.lpszMenuName=Null
  335. _dc.lpszClassName=_dname.ToWString()
  336. _dc.cbWndExtra=DLGWINDOWEXTRA
  337. ClassAtom2=RegisterClassW(_dc)
  338. EndIf
  339. Return _dname
  340. EndFunction
  341. 'TMaxGuiDriver interface
  342. Method CreateGadget:TGadget(class,Text$,x,y,w,h,group:TGadget,style)
  343. Select class
  344. Case GADGET_WINDOW
  345. If Not group group=GDIDesktop
  346. End Select
  347. Local gadget:TGadget = GadgetInstanceFromClass(class,group,style,Text)
  348. Select class
  349. Case GADGET_DESKTOP, GADGET_MENUITEM, GADGET_NODE
  350. Return gadget
  351. End Select
  352. If LocalizationMode() & LOCALIZATION_OVERRIDE Then
  353. LocalizeGadget(gadget,Text,"")
  354. Else
  355. gadget.SetText(Text)
  356. EndIf
  357. If group Then gadget._SetParent group
  358. If class <> GADGET_TOOLBAR Then gadget.SetShape(x,y,w,h)
  359. 'v0.51: Gadgets are now only shown when they have been sized, and the text set.
  360. If TWindowsGadget(gadget) Then
  361. If Not TWindowsWindow(gadget)
  362. gadget.SetFont(GDIFont)
  363. If TWindowsGadget(group) Then
  364. TWindowsGadget(gadget)._forceDisable = Not( TWindowsGadget(group)._enabled And Not TWindowsGadget(group)._forceDisable )
  365. gadget.SetEnabled(Not (gadget.State()&STATE_DISABLED))
  366. EndIf
  367. gadget.SetShow(True)
  368. ElseIf Not (style & WINDOW_HIDDEN) Then
  369. gadget.SetShow(True)
  370. EndIf
  371. EndIf
  372. If TWindowsGadget(gadget) Then TWindowsGadget(gadget).Sensitize()
  373. Return gadget
  374. EndMethod
  375. Method GadgetInstanceFromClass:TGadget(class, group:TGadget, style = 0, Text$ = "")
  376. Local gadget:TGadget
  377. Select class
  378. Case GADGET_DESKTOP
  379. gadget=GDIDesktop
  380. Case GADGET_MENUITEM
  381. gadget=New TWindowsMenu.Create(group,style,Text)
  382. Case GADGET_WINDOW
  383. gadget=New TWindowsWindow.Create(group,style)
  384. Case GADGET_BUTTON
  385. gadget=New TWindowsButton.Create(group,style)
  386. Case GADGET_TEXTFIELD
  387. gadget=New TWindowsTextField.Create(group,style,Text)
  388. Case GADGET_TEXTAREA
  389. gadget=New TWindowsTextArea.Create(group,style)
  390. Case GADGET_COMBOBOX
  391. gadget=New TWindowsComboBox.Create(group,style,Text)
  392. Case GADGET_LISTBOX
  393. gadget=New TWindowsListBox.Create(group,style)
  394. Case GADGET_TOOLBAR
  395. gadget=New TWindowsToolBar.Create(group,style,Text)
  396. Case GADGET_TABBER
  397. gadget=New TWindowsTabber.Create(group,style)
  398. Case GADGET_NODE
  399. gadget=New TWindowsTreeNode.Create(group,style,Text)
  400. Case GADGET_TREEVIEW
  401. gadget=New TWindowsTreeView.Create(group,style)
  402. Case GADGET_LABEL
  403. gadget=New TWindowsLabel.Create(group,style)
  404. Case GADGET_SLIDER
  405. gadget=New TWindowsSlider.Create(group,style)
  406. Case GADGET_PROGBAR
  407. gadget=New TWindowsProgressBar.Create(group,style)
  408. Case GADGET_PANEL
  409. gadget=New TWindowsPanel.Create(group,style)
  410. Case GADGET_CANVAS
  411. gadget=New TWindowsPanel.Create(group,style|PANEL_CANVAS|PANEL_ACTIVE)
  412. Case GADGET_HTMLVIEW
  413. gadget=New TWindowsHTMLView.Create(group,style)
  414. End Select
  415. Return gadget
  416. EndMethod
  417. Method ActiveGadget:TGadget()
  418. Local tmpHwnd:Int = GetFocus(), tmpGadget:TGadget
  419. While tmpHwnd
  420. tmpGadget = GadgetFromHwnd( tmpHwnd )
  421. If tmpGadget Then Exit
  422. tmpHwnd = GetParent_(tmpHwnd)
  423. Wend
  424. Return tmpGadget
  425. EndMethod
  426. Method RequestColor(red,green,blue)
  427. Local cc:CHOOSECOLOR = New CHOOSECOLOR
  428. cc.lStructSize=SizeOf(cc)
  429. cc.hwndOwner=GetActiveHwnd()
  430. cc.rgbResult=(red)|(green Shl 8)|(blue Shl 16)
  431. cc.lpCustColors=_customcolors
  432. cc.Flags=CC_RGBINIT|CC_FULLOPEN|CC_ANYCOLOR
  433. Local hwnd = GetFocus()
  434. Local n = ChooseColorW(cc)
  435. SetFocus(hwnd)
  436. If Not n Return 0
  437. n = ((cc.rgbResult Shr 16)&$ff) | (cc.rgbResult&$ff00) | ((cc.rgbResult Shl 16)&$ff0000)
  438. Return n|$ff000000
  439. EndMethod
  440. Method LookupColor( colorindex:Int, red:Byte Var, green:Byte Var, blue:Byte Var )
  441. Select colorindex
  442. Case GUICOLOR_WINDOWBG
  443. colorindex = COLOR_BTNFACE
  444. Case GUICOLOR_GADGETBG
  445. colorindex = COLOR_WINDOW
  446. Case GUICOLOR_GADGETFG
  447. colorindex = COLOR_WINDOWTEXT
  448. Case GUICOLOR_LINKFG
  449. colorindex = COLOR_HOTLIGHT
  450. Case GUICOLOR_SELECTIONBG
  451. colorindex = COLOR_HIGHLIGHT
  452. Default
  453. Return Super.LookupColor( colorindex, red, green, blue )
  454. EndSelect
  455. Local tmpColor:Int = GetSysColor( colorindex )
  456. red = tmpColor & $FF
  457. green = (tmpColor Shr 8) & $FF
  458. blue = (tmpColor Shr 16) & $FF
  459. Return True
  460. EndMethod
  461. Method LoadFont:TGuiFont(name$,size,flags)
  462. Return New TWindowsFont.Load(name,Double(size),flags)
  463. EndMethod
  464. Method LoadFontWithDouble:TGuiFont(name$,size:Double,flags)
  465. Return New TWindowsFont.Load(name,size,flags)
  466. EndMethod
  467. Method LibraryFont:TGuiFont( pFontType% = GUIFONT_SYSTEM, pFontSize:Double = 0, pFontStyle% = FONT_NORMAL )
  468. If pFontType = GUIFONT_SYSTEM Then Return TWindowsFont.DefaultFont( pFontSize, pFontStyle ) Else Return Super.LibraryFont( pFontType, pFontSize, pFontStyle )
  469. EndMethod
  470. Method RequestFont:TGuiFont(font:TGuiFont)
  471. Return TWindowsFont.Request(font)
  472. EndMethod
  473. Method SetPointer(shape)
  474. Global winptrs[]=[0,32512,32513,32514,32515,32516,32642,32643,32644,32645,32646,32648,32649,32650,32651]
  475. If shape<1 Or shape>14 Then _cursor = LoadCursorW( 0,Short Ptr( IDC_ARROW ) ) Else _cursor=LoadCursorW(0,Short Ptr(winptrs[shape]))
  476. SetCursor(_cursor)
  477. If TWindowsTextArea._oldCursor Then TWindowsTextArea._oldCursor = _cursor
  478. If shape = 0 Then _cursor = 0
  479. EndMethod
  480. Method LoadIconStrip:TIconStrip(source:Object)
  481. Return TWindowsIconStrip.Create(source)
  482. EndMethod
  483. Function CheckCommonControlVersion() 'Returns True if supports alpha/themes etc. or False if not.
  484. If Not _commoncontrolversion Then
  485. Local libComCtl = LoadLibraryW("comctl32.dll")
  486. Local GetCommonControlVersion( pDllVersionInfo:Byte Ptr ) "win32" = GetProcAddress(libComCtl, "DllGetVersion")
  487. If GetCommonControlVersion Then
  488. Local tmpDllVersion:DLLVERSIONINFO2 = New DLLVERSIONINFO2
  489. GetCommonControlVersion( tmpDllVersion )
  490. _commoncontrolversion = [tmpDllVersion.dwMajorVersion,tmpDllVersion.dwMinorVersion,tmpDLLVersion.dwBuildNo]
  491. EndIf
  492. GetCommonControlVersion = Null
  493. FreeLibrary( libComCtl )
  494. EndIf
  495. If _commoncontrolversion And _commoncontrolversion[0] >= 6 Then
  496. If (_commoncontrolversion[0] > 6) Or (_commoncontrolversion[1] > 0) Then Return 2 Else Return 1
  497. EndIf
  498. EndFunction
  499. Function GetThemeHandle(hwnd, pClass$ = "WINDOW")
  500. If OpenThemeData And CheckCommonControlVersion() Then Return OpenThemeData(hwnd, pClass)
  501. EndFunction
  502. Function CloseThemeHandle(hTheme)
  503. If CloseThemeData Then Return CloseThemeData(hTheme)
  504. EndFunction
  505. Function CreateExplorerStyleGadgets( pDisable = False )
  506. _explorerstyle = (pDisable <> True)
  507. EndFunction
  508. Function GetActiveHwnd()
  509. If _activeWindow Then Return _activeWindow._hwnd Else Return GetActiveWindow()
  510. EndFunction
  511. EndType
  512. Type TWindowsGadget Extends TGadget
  513. 'Flag that determines whether gadgets should redraw when they are resized (see Rethink()).
  514. Global _resizeRedraw = True
  515. 'Generic Unicode Strings to prevent memory-leak
  516. Global _wstrEmpty:Short Ptr = "".ToWString()
  517. Global _wstrSpace:Short Ptr = " ".ToWString()
  518. Global _wstrExplorer:Short Ptr = "Explorer".ToWString()
  519. 'Important gadget fields that store OS control handles etc..
  520. Field _class, _hwnd, _hwndclient, _tooltips
  521. Field _proc(hwnd,msg,wp,lp) "win32"
  522. Field _hotkey:THotKey
  523. Field _oldcursorlp 'Should track events
  524. Field _sensitive% = False 'Determines whether gadgets should generate events.
  525. 'Not to be confused with the sensitivity field of TGadget
  526. 'which specifies which type of events are fired.
  527. 'Aesthetics
  528. Field _bgbrush, _fgcolor = -1, _bgcolor = -1 'Background colour
  529. Field _hbrush, _hbitmap 'Background colour
  530. Field _bitmap 'Background bitmap
  531. Field _iconBitmap 'Icon bitmap
  532. Field _hTheme 'Open handle to XP Theme API (for use in button's WM_DRAWITEM etc.)
  533. Field _font:TWindowsFont 'Font (needs to be stored, otherwise it may be collected by GC)
  534. Field _wstrTooltip:Short Ptr, _toolAdded = False
  535. Field _clientX:Int, _clientY:Int, _enabled:Int = True, _forcedisable:Int = False
  536. Method Create:TWindowsGadget(group:TGadget, style, Text$="") Abstract
  537. Method SetColor(red,green,blue)
  538. If _bgbrush Then DeleteObject _bgbrush
  539. _bgcolor = (blue Shl 16) | (green Shl 8) | red
  540. _bgbrush=CreateSolidBrush(_bgcolor)
  541. RedrawGadget(Self)
  542. EndMethod
  543. Method RemoveColor()
  544. If _bgbrush Then DeleteObject _bgbrush
  545. _bgbrush=0
  546. RedrawGadget(Self)
  547. EndMethod
  548. Method FgColor()
  549. Return _fgcolor
  550. EndMethod
  551. Method BgColor()
  552. Return _bgcolor
  553. EndMethod
  554. Method BgBrush()
  555. Return _bgbrush
  556. EndMethod
  557. Method SetTextColor(r,g,b)
  558. _fgcolor = (b Shl 16) | (g Shl 8) | r
  559. RedrawGadget(Self)
  560. EndMethod
  561. Method Query(queryid)
  562. Select queryid
  563. Case QUERY_HWND
  564. Return _hwnd
  565. Case QUERY_HWND_CLIENT
  566. If _hwndclient Return _hwndclient
  567. Return _hwnd
  568. End Select
  569. EndMethod
  570. Method Register(class,hwnd,hwndclient=0,tips=False)
  571. _class=class
  572. _hwnd=hwnd
  573. _hwndclient=hwndclient
  574. TWindowsGUIDriver.RegisterHwnd(_hwnd,Self)
  575. If _hwndclient TWindowsGUIDriver.RegisterHwnd(_hwndclient,Self)
  576. Local atom=GetClassLongW(hwnd,GCW_ATOM)
  577. If atom<>TWindowsGUIDriver.ClassAtom And atom<>TWindowsGUIDriver.ClassAtom2 And Not _proc
  578. _proc=Byte Ptr(SetWindowLongW(hwnd,GWL_WNDPROC,Int Byte Ptr TWindowsGUIDriver.ClassWndProc))
  579. EndIf
  580. If tips Then SetupToolTips()
  581. EndMethod
  582. Method SetupToolTips()
  583. If _tooltips Then DestroyWindow _tooltips;TWindowsGUIDriver.RemoveHwnd(_tooltips);_tooltips = 0
  584. _tooltips = CreateWindowExW( 0,"tooltips_class32","",TTS_ALWAYSTIP,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,_hwnd,0,GetModuleHandleW(Null),Null )
  585. SendMessageW _tooltips,TTM_SETMAXTIPWIDTH,0,300
  586. TWindowsGUIDriver.RegisterHwnd( _tooltips, Self )
  587. EndMethod
  588. Method isTabbable()
  589. Local style:Int = GetWindowLongW(_hwnd,GWL_STYLE)&(WS_TABSTOP|WS_CHILD)
  590. Return (style=(WS_TABSTOP|WS_CHILD))
  591. EndMethod
  592. Method isControl()
  593. Return (GetWindowLongW(_hwnd,GWL_STYLE)&(WS_CHILD)=WS_CHILD)
  594. EndMethod
  595. Method Activate(cmd)
  596. Select cmd
  597. Case ACTIVATE_FOCUS
  598. If isTabbable()
  599. DefDlgProcW GetParent_(_hwnd),WM_NEXTDLGCTL,_hwnd,1
  600. Return 1
  601. EndIf
  602. Return SetFocus(_hwnd)
  603. Case ACTIVATE_BACK
  604. Return SendMessageW(_hwnd,WM_NEXTDLGCTL,1,0)
  605. Case ACTIVATE_FORWARD
  606. Return SendMessageW(_hwnd,WM_NEXTDLGCTL,0,0)
  607. Case ACTIVATE_REDRAW
  608. RefreshLook()
  609. Return RedrawWindow( _hwnd, Null, Null, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN )
  610. End Select
  611. EndMethod
  612. Method Rethink()
  613. QueueResize(_hwnd,xpos,ypos,width,height)
  614. EndMethod
  615. Method RethinkClient(forceRedraw:Int = False)
  616. EndMethod
  617. Method SetArea(x,y,w,h)
  618. SetRect(x,y,w,h)
  619. Rethink()
  620. EndMethod
  621. Method LayoutKids()
  622. StartResize()
  623. 'Implemented hack to speed-up drawing considerably...
  624. Local tmpOldState = TWindowsGadget._resizeredraw
  625. TWindowsGadget._resizeredraw = False
  626. 'Child windows are laid-out like normal...
  627. Super.LayoutKids()
  628. 'Reposition all child gadgets together.
  629. EndResize()
  630. 'If this control is the first parent who started the resizing, then redraw parent and all controls now.
  631. If tmpOldState Then
  632. If (Not kids.IsEmpty()) Then Activate(ACTIVATE_REDRAW)
  633. TWindowsGadget._resizeredraw = True
  634. EndIf
  635. EndMethod
  636. Method ClientWidth()
  637. Local Rect[] = [xpos,ypos,xpos+width,ypos+height]
  638. SendMessageW Query(QUERY_HWND), WM_NCCALCSIZE, False, Int Byte Ptr Rect
  639. Return Rect[2]-Rect[0]-_clientX
  640. EndMethod
  641. Method ClientHeight()
  642. Local Rect[] = [xpos,ypos,xpos+width,ypos+height]
  643. SendMessageW Query(QUERY_HWND), WM_NCCALCSIZE, False, Int Byte Ptr Rect
  644. Return Rect[3]-Rect[1]-_clientY
  645. EndMethod
  646. Method SetText(Text$)
  647. Desensitize()
  648. SetWindowTextW _hwnd, Text
  649. Sensitize()
  650. EndMethod
  651. Method GetText$()
  652. Local strText:Short[GetWindowTextLengthW(_hwnd)+1] 'Must include NULL terminator.
  653. GetWindowTextW _hwnd, strText, strText.length
  654. Return String.FromWString( strText )
  655. EndMethod
  656. Method SetFont(font:TGuiFont)
  657. If TWindowsFont(font) Then _font = TWindowsFont(font) Else _font = TWindowsGUIDriver.GDIFont
  658. SendMessageW _hwnd,WM_SETFONT,font.handle,1
  659. EndMethod
  660. Method SetShow(show)
  661. If show
  662. ShowWindow _hwnd,SW_SHOW
  663. Else
  664. 'Requester fix - ShowWindow activates the last activated window when an active window is hidden, so if
  665. 'a file requester/child gadget was the last window to be activated, then the program will lose focus as it is
  666. 'trying to activate a non-existent window.
  667. If parent And HasDescendant(ActiveGadget()) Then ActivateGadget(parent)
  668. ShowWindow _hwnd,SW_HIDE
  669. EndIf
  670. EndMethod
  671. Method SetEnabled(enable)
  672. _enabled = enable
  673. enable = enable And Not _forceDisable
  674. If Not((EnableWindow(_hwnd,enable)<>0) ~ enable) Then
  675. For Local tmpGadget:TWindowsGadget = EachIn kids
  676. tmpGadget._forceDisable = Not enable
  677. If tmpGadget.isControl() Then tmpGadget.SetEnabled(tmpGadget._enabled)
  678. Next
  679. EndIf
  680. EndMethod
  681. Method SetTooltip( pTooltip$ )
  682. If _wstrTooltip Then MemFree _wstrTooltip;_wstrTooltip = Null
  683. Local tmpToolInfo:TOOLINFOW = New TOOLINFOW
  684. tmpToolInfo.cbSize = SizeOf(tmpToolInfo)
  685. tmpToolInfo.hwnd = GetParent_(_hwnd)
  686. tmpToolInfo.hinst = GetModuleHandleW(Null)
  687. tmpToolInfo.uID = _hwnd
  688. If pTooltip Then
  689. _wstrTooltip = pTooltip.Replace("~r","").Replace("~n","~r~n").ToWString()
  690. tmpToolInfo.uFlags = TTF_IDISHWND|TTF_TRANSPARENT|TTF_SUBCLASS
  691. tmpToolInfo.lpszText = _wstrTooltip
  692. If Not _toolAdded Then
  693. _toolAdded = SendMessageW(TWindowsGUIDriver._hwndTooltips, TTM_ADDTOOLW, 0, Int Byte Ptr tmpToolInfo)
  694. Else
  695. SendMessageW(TWindowsGUIDriver._hwndTooltips, TTM_UPDATETIPTEXTW, 0, Int Byte Ptr tmpToolInfo)
  696. EndIf
  697. ElseIf _tooladded Then
  698. SendMessageW(TWindowsGUIDriver._hwndTooltips, TTM_DELTOOLW, 0, Int Byte Ptr tmpToolInfo )
  699. _toolAdded = 0
  700. EndIf
  701. EndMethod
  702. Method GetTooltip$()
  703. If _wstrTooltip Then Return String.FromWString(_wstrTooltip)
  704. EndMethod
  705. Method State()
  706. Local t, style = GetWindowLongW(_hwnd, GWL_STYLE)
  707. If Not (style&WS_VISIBLE) Then t:|STATE_HIDDEN
  708. If Not _enabled Then t:|STATE_DISABLED
  709. Return t
  710. EndMethod
  711. Method Free()
  712. If _tooltips Then DestroyWindow _tooltips;_tooltips=0
  713. SetTooltip("") 'Free any tooltip memory allocations
  714. If _hwnd Then DestroyWindow _hwnd;TWindowsGUIDriver.RemoveHwnd(_hwnd);_hwnd=0
  715. If _hwndclient Then TWindowsGUIDriver.RemoveHwnd(_hwndclient);_hwndclient=0
  716. FlushBrushes(False)
  717. If _hotKey Then RemoveHotKey(_hotKey);_hotKey = Null
  718. If _iconBitmap Then DeleteObject(_iconBitmap);_iconBitmap = 0
  719. If _bitmap Then DeleteObject(_bitmap);_bitmap = 0
  720. If _bgbrush Then DeleteObject(_bgbrush);_bgbrush = 0
  721. If _htheme Then TWindowsGUIDriver.CloseThemeHandle(_hTheme);_hTheme = 0
  722. _font = Null
  723. _SetParent Null
  724. EndMethod
  725. Method OnNotify(wp,lp)
  726. EndMethod
  727. Method WndProc(hwnd,msg,wp,lp)
  728. Select msg
  729. Case WM_WINDOWPOSCHANGING
  730. FlushBrushes()
  731. EndSelect
  732. If _proc And _hwnd = hwnd Then
  733. Return CallWindowProcW(_proc,hwnd,msg,wp,lp) 'fixed auto scrollbars
  734. EndIf
  735. Return DefWindowProcW( hwnd,msg,wp,lp )
  736. EndMethod
  737. Method OnCommand(msg,wp)
  738. EndMethod
  739. Method OnDrawItem( pDrawItemStruct:DRAWITEMSTRUCT )
  740. EndMethod
  741. Method SetHotKey(key,modifier)
  742. Local ev:TEvent = CreateEvent( EVENT_GADGETACTION,Self )
  743. If _hotKey Then RemoveHotKey(_hotKey);_hotKey = Null
  744. If key Then _hotkey=SetHotKeyEvent(key,modifier,ev,FindGadgetWindowHwnd(Self))
  745. EndMethod
  746. 'Slow back-up code for mimicking transparency for PANEL_GROUPs and when
  747. 'DrawThemeParentBackground() is not available (i.e. on Windows 9x/2000).
  748. Method CreateControlBrush( hWndControl, hdc = 0 )
  749. Local xOffset, yOffset
  750. Local hwndWindow = GetParent_(hwndControl)
  751. Local rectWindow[4], rectControl[4], rectClient[4]
  752. If _hbrush Then Return _hbrush
  753. If BgBrush() Then
  754. If hdc Then SetBkColor(hdc, BgColor())
  755. Return BgBrush()
  756. EndIf
  757. Local tmpDC = GetDC( hwndWindow )
  758. 'Fix required to offset background when controls are drawn with WS_EX_CLIENTEDGE (e.g. panel with PANEL_SUNKEN/PANEL_RAISED set)
  759. If GetWindowLongW(hwndWindow,GWL_EXSTYLE)&(WS_EX_CLIENTEDGE|WS_EX_WINDOWEDGE) Then
  760. xOffset = -GetSystemMetrics(SM_CXEDGE)
  761. yOffset = -GetSystemMetrics(SM_CYEDGE)
  762. EndIf
  763. GetClientRect( hwndControl, rectClient )
  764. GetWindowRect( hwndWindow, rectWindow )
  765. GetWindowRect( hwndControl, rectControl )
  766. Local x = rectControl[0]-rectWindow[0]
  767. Local y = rectControl[1]-rectWindow[1]
  768. Local w = rectControl[2]-rectControl[0]
  769. Local h = rectControl[3]-rectControl[1]
  770. Local dcBitmap = CreateCompatibleDC( tmpDC )
  771. Local bkgndBitmap = CreateCompatibleBitmap( tmpDC, rectWindow[2]-rectWindow[0], rectWindow[3]-rectWindow[1] )
  772. SelectObject( dcBitmap, bkgndBitmap )
  773. 'InvalidateRect( hwndWindow, Null, False )
  774. SendMessageW hwndWindow, WM_ERASEBKGND, dcBitmap, 0
  775. Local bkgndClientBitmap = CreateCompatibleBitmap( tmpDC, w, h )
  776. Local dcClientBitmap = CreateCompatibleDC( tmpDC )
  777. SelectObject( dcClientBitmap, bkgndClientBitmap )
  778. BitBlt( dcClientBitmap, 0,0 , w, h, dcBitmap, x+xOffset, y+yOffset, ROP_SRCCOPY )
  779. DeleteObject( bkgndBitmap )
  780. DeleteDC( dcBitmap )
  781. DeleteDC( dcClientBitmap )
  782. _hbrush = CreatePatternBrush( bkgndClientBitmap )
  783. _hbitmap = bkgndClientBitmap
  784. ReleaseDC( hwndWindow, tmpDC )
  785. Return _hbrush
  786. EndMethod
  787. 'Clears the parent background brushes.
  788. Method FlushBrushes(pRecurse:Int = True)
  789. Local tmpChanges:Int = 0
  790. If _hbrush Then
  791. DeleteObject( _hbrush )
  792. _hbrush = 0
  793. tmpChanges:|True
  794. EndIf
  795. If _hBitmap Then
  796. DeleteObject( _hBitmap )
  797. _hBitmap = 0
  798. tmpChanges:|True
  799. EndIf
  800. Return tmpChanges
  801. EndMethod
  802. 'Method that returns a brush for drawing backgrounds.
  803. Method DrawBackground( hdc, hwnd )
  804. If BgBrush() Then SetBkColor(hdc, BgColor());Return BgBrush()
  805. Return DrawParentBackground( hdc, hwnd )
  806. EndMethod
  807. 'Another method which mimics transparency on Windows Controls.
  808. Function DrawParentBackground( hdc, hwndControl, pForceHack = False )
  809. Local rectWindow[4], rectControl[4], rectClient[4]
  810. Local hwndWindow = GetParent_(hwndControl)
  811. GetClientRect( hwndControl, rectClient )
  812. GetClientRect( hwndWindow, rectWindow )
  813. GetWindowRect( hwndControl, rectControl )
  814. 'Ensures that the the drawing context is returned in exactly the same state that it was passed.
  815. Local tmpSaveState = SaveDC( hdc )
  816. If DrawThemeParentBackground And Not pForceHack Then
  817. DrawThemeParentBackground(hwndControl,hdc,rectClient)
  818. Else 'Again, slow back-up code in case DrawThemeParentBackground() is not available.
  819. Local tmpDC, xOffset, yOffset
  820. 'Fix required to offset background when controls are drawn with WS_EX_CLIENTEDGE (e.g. panel with PANEL_BORDER set)
  821. If GetWindowLongW(hwndWindow,GWL_EXSTYLE)&WS_EX_CLIENTEDGE Then
  822. xOffset = -GetSystemMetrics(SM_CXEDGE)
  823. yOffset = -GetSystemMetrics(SM_CYEDGE)
  824. EndIf
  825. tmpDC = GetDC( hwndWindow )
  826. ScreenToClient( hwndWindow, rectControl )
  827. ScreenToClient( hwndWindow, Int Ptr (rectControl)+2 )
  828. Local x = rectControl[0]+rectClient[0]
  829. Local y = rectControl[1]+rectClient[1]
  830. Local w = rectClient[2]-rectClient[0]
  831. Local h = rectClient[3]-rectClient[1]
  832. Local bkgndBitmap = CreateCompatibleBitmap( tmpDC, rectWindow[2]-rectWindow[0], rectWindow[3]-rectWindow[1] )
  833. Local dcBitmap = CreateCompatibleDC( tmpDC )
  834. SelectObject( dcBitmap, bkgndBitmap )
  835. InvalidateRect( hwndWindow, Null, False )
  836. SendMessageW hwndWindow, WM_ERASEBKGND, dcBitmap, 0
  837. BitBlt( hdc, 0,0 , w, h, dcBitmap, x+xOffset, y+yOffset, ROP_SRCCOPY )
  838. DeleteObject( bkgndBitmap )
  839. DeleteDC( dcBitmap )
  840. ReleaseDC( hwndWindow, tmpDC )
  841. EndIf
  842. 'Ensures that the the drawing context is returned in exactly the same state that it was passed.
  843. RestoreDC( hdc, tmpSaveState )
  844. Return GetStockObject( NULL_BRUSH )
  845. EndFunction
  846. Method Sensitize()
  847. _sensitive = True
  848. EndMethod
  849. Method DeSensitize()
  850. _sensitive = False
  851. EndMethod
  852. Method PostGuiEvent( pID%, pData%=0, pMods%=0, pX%=0, pY%=0, pExtra:Object = Null)
  853. Select True
  854. Case TWindowsListBox(Self) <> Null, TWindowsTabber(Self) <> Null, TWindowsToolbar(Self) <> Null, TWindowsCombobox(Self) <> Null
  855. If pData>-1 Then
  856. If (ItemFlags(pData) & GADGETITEM_TOGGLE) Then SelectItem(pData,2)
  857. EndIf
  858. End Select
  859. If _sensitive Then MaxGUI.MaxGUI.PostGuiEvent( pID, Self, pData, pMods, pX, pY, pExtra )
  860. EndMethod
  861. 'Resize Methods
  862. Field hdwpStruct
  863. Method StartResize()
  864. If Not hdwpStruct Then
  865. Local tmpCount = kids.Count()
  866. If tmpCount Then hdwpStruct = BeginDeferWindowPos( tmpCount )
  867. EndIf
  868. EndMethod
  869. Method QueueResize( hwnd, xpos, ypos, width, height )
  870. If parent And GetParent_(hwnd) = parent.Query(QUERY_HWND_CLIENT) And TWindowsGadget(parent).hdwpStruct Then
  871. Local tmpFlags = SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOACTIVATE' | SWP_NOCOPYBITS
  872. If Not _resizeRedraw Then tmpFlags:| SWP_NOREDRAW
  873. TWindowsGadget(parent).hdwpStruct = DeferWindowPos( TWindowsGadget(parent).hdwpStruct, hwnd, Null, xpos, ypos, width, height, tmpFlags )
  874. Else
  875. MoveWindow( hwnd, xpos, ypos, width, height, _resizeRedraw )
  876. HasResized()
  877. EndIf
  878. EndMethod
  879. Method EndResize()
  880. If hdwpStruct Then
  881. EndDeferWindowPos( hdwpStruct );hdwpStruct = 0
  882. For Local tmpGadget:TWindowsGadget = EachIn kids
  883. Sensitize()
  884. tmpGadget.HasResized()
  885. Next
  886. EndIf
  887. EndMethod
  888. 'Required for resizing columns in listboxes (has to be done outside WM_SIZE)
  889. Method HasResized()
  890. EndMethod
  891. 'Required to ensure problematic controls are updated when parent aesthetics are changed:
  892. Method RefreshLook()
  893. FlushBrushes(False)
  894. For Local tmpGadget:TWindowsGadget = EachIn kids
  895. tmpGadget.RefreshLook()
  896. Next
  897. EndMethod
  898. Rem
  899. Method StartDoubleBuffer()
  900. For Local tmpGadget:TWindowsGadget = EachIn kids
  901. tmpGadget.StartDoubleBuffer()
  902. Next
  903. EndMethod
  904. Method EndDoubleBuffer()
  905. For Local tmpGadget:TWindowsGadget = EachIn kids
  906. tmpGadget.EndDoubleBuffer()
  907. Next
  908. EndMethod
  909. EndRem
  910. EndType
  911. Type TWindowsDesktop Extends TWindowsGadget
  912. Method New()
  913. Local Rect[4]
  914. Local hwnd = GetDesktopWindow()
  915. Register(GADGET_DESKTOP,hwnd,0,False)
  916. GetClientRect hwnd,Rect
  917. SetShape 0,0,Rect[2]-Rect[0],Rect[3]-Rect[1]
  918. EndMethod
  919. Method Create:TWindowsGadget(group:TGadget,style,Text$="")
  920. Return Self
  921. EndMethod
  922. Method SetTooltip( pTooltip$ )
  923. 'Shouldn't have tool-tips.
  924. EndMethod
  925. Method Free()
  926. 'Can't be free'd.
  927. EndMethod
  928. Method Class()
  929. Return GADGET_DESKTOP
  930. EndMethod
  931. Method ClientHeight()
  932. Local Rect[4]
  933. If Super.ClientHeight() = height And SystemParametersInfoW( SPI_GETWORKAREA, 0, Int Byte Ptr Rect, 0 )
  934. Return Rect[3]-Rect[1]
  935. Else
  936. Return Super.ClientHeight()
  937. EndIf
  938. EndMethod
  939. Method ClientWidth()
  940. Local Rect[4]
  941. If Super.ClientWidth() = width And SystemParametersInfoW( SPI_GETWORKAREA, 0, Int Byte Ptr Rect, 0 )
  942. Return Rect[2]-Rect[0]
  943. Else
  944. Return Super.ClientWidth()
  945. EndIf
  946. EndMethod
  947. EndType
  948. Type TWindowsWindow Extends TWindowsGadget
  949. Field _wstyle, _xstyle
  950. Field _minwidth,_minheight,_maxwidth = -1,_maxheight = -1
  951. Field _menu:TWindowsMenu
  952. Field _hmenu
  953. Field _status
  954. Method Create:TWindowsGadget(group:TGadget,style,Text$="")
  955. Local hwnd, parent, client
  956. Local classname$ = TWindowsGUIDriver.ClassName()
  957. Self.style = style
  958. _wstyle=WS_CLIPSIBLINGS|WS_CLIPCHILDREN
  959. If group Then parent = group.Query(QUERY_HWND)
  960. If (style&WINDOW_TITLEBAR)
  961. _wstyle:|WS_OVERLAPPED|WS_SYSMENU
  962. If style&WINDOW_RESIZABLE _wstyle:|WS_MINIMIZEBOX|WS_MAXIMIZEBOX
  963. If group <> TWindowsGUIDriver.GDIDesktop And Not (style&WINDOW_TOOL) Then
  964. classname$ = TWindowsGUIDriver.DialogClassName()
  965. _xstyle:|WS_EX_DLGMODALFRAME
  966. EndIf
  967. Else
  968. _wstyle:|WS_POPUP
  969. EndIf
  970. If style&WINDOW_RESIZABLE Then _wstyle:|WS_SIZEBOX
  971. If style&WINDOW_MENU Then _hmenu=CreateMenu_();AppendMenuW( _hmenu,MF_STRING,Null,_wstrEmpty )
  972. If style&WINDOW_TOOL Then _xstyle:|WS_EX_TOOLWINDOW
  973. ' Note: No WINDOW_HIDDEN case as gadgets are always created hidden to hide initial resize flicker.
  974. ' TWindowsGUIDriver.CreateGadget() will later show window if WINDOW_HIDDEN is not specified.
  975. hwnd=CreateWindowExW(_xstyle,classname,"",_wstyle,0,0,0,0,parent,_hmenu,GetModuleHandleW(Null),Null)
  976. If style&WINDOW_STATUS
  977. _status=CreateWindowExW(0,"msctls_statusbar32","",WS_CHILD|WS_VISIBLE,0,0,0,0,hwnd,0,GetModuleHandleW(Null),Null)
  978. SetWindowPos( _status, HWND_TOPMOST,0,0,0,0,SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOOWNERZORDER|SWP_NOSIZE)
  979. EndIf
  980. client=CreateWindowExW(0,TWindowsGUIDriver.ClassName(),"",WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,0,0,0,0,hwnd,0,GetModuleHandleW(Null),Null)
  981. Register GADGET_WINDOW,hwnd,client,False
  982. If style&WINDOW_ACCEPTFILES Then DragAcceptFiles _hwnd,True
  983. _wstyle = GetWindowLongW( hwnd, GWL_STYLE )
  984. Return Self
  985. EndMethod
  986. Method SetAlpha( alpha# )
  987. If SetLayeredWindowAttributes Then
  988. Local tmpStyle% = GetWindowLongW(_hwnd, GWL_EXSTYLE)
  989. If alpha = 1.0 Then
  990. SetLayeredWindowAttributes( _hwnd, 0, Byte(alpha*255), LWA_ALPHA)
  991. If (tmpStyle & WS_EX_LAYERED) Then SetWindowLongW(_hwnd, GWL_EXSTYLE, tmpStyle&~WS_EX_LAYERED)
  992. Else
  993. If Not (tmpStyle & WS_EX_LAYERED) Then SetWindowLongW(_hwnd, GWL_EXSTYLE, tmpStyle|WS_EX_LAYERED)
  994. SetLayeredWindowAttributes( _hwnd, 0, Byte(alpha*255), LWA_ALPHA)
  995. EndIf
  996. RedrawGadget(Self)
  997. EndIf
  998. EndMethod
  999. Method Rethink()
  1000. Local dimensions[] = [xpos,ypos,width,height]
  1001. ConvertToContainerDimensions( dimensions[0], dimensions[1], dimensions[2], dimensions[3] )
  1002. MoveWindow _hwnd, dimensions[0], dimensions[1], dimensions[2], dimensions[3], True
  1003. RethinkClient(True)
  1004. EndMethod
  1005. Method RethinkClient(forceRedraw:Int = False)
  1006. If _hwndClient Then
  1007. MoveWindow _hwndClient, _clientx,_clienty,ClientWidth(),ClientHeight(),forceRedraw
  1008. EndIf
  1009. LayoutKids()
  1010. EndMethod
  1011. Method ClientWidth()
  1012. If (style & WINDOW_CLIENTCOORDS) Then Return width
  1013. Local Rect:Int[4]
  1014. GetClientRect _hwnd, Rect
  1015. Return Max(Rect[2]-Rect[0]-_clientX,0)
  1016. EndMethod
  1017. Method ClientHeight()
  1018. If (style & WINDOW_CLIENTCOORDS) Then Return height
  1019. Local h:Int = height, Rect:Int[] = [0,0,width,height]
  1020. AdjustWindowRectEx(Rect,GetWindowLongW(_hwnd, GWL_STYLE),_hmenu,GetWindowLongW(_hwnd, GWL_EXSTYLE))
  1021. h:-(Rect[3]-Rect[1]+_clientY-height)
  1022. If _status Then GetWindowRect _status,Rect;h:-(Rect[3]-Rect[1])
  1023. Return Max(h,0)
  1024. End Method
  1025. Method Class()
  1026. Return GADGET_WINDOW
  1027. EndMethod
  1028. Method State()
  1029. Local t = Super.State()
  1030. If IsIconic(_hwnd) t:|STATE_MINIMIZED
  1031. If IsZoomed(_hwnd) t:|STATE_MAXIMIZED
  1032. Return t
  1033. EndMethod
  1034. Method SetEnabled(enable)
  1035. _enabled = enable
  1036. EnableWindow(_hwnd,enable)
  1037. EndMethod
  1038. Method SetMinimumSize(w,h)
  1039. 'Set minimum size for current window style
  1040. _minwidth=w;_minheight=h
  1041. 'Get window style
  1042. Local tmpWStyle% = GetWindowLongW( _hwnd, GWL_STYLE )
  1043. 'Update size border
  1044. If (_maxwidth = _minwidth And _maxheight = _minheight) Then tmpWStyle:&~WS_SIZEBOX ElseIf (style&WINDOW_RESIZABLE) Then tmpWStyle:|WS_SIZEBOX
  1045. 'Set new window style if necessary
  1046. If tmpWStyle <> GetWindowLongW( _hwnd, GWL_STYLE ) Then
  1047. SetWindowLongW( _hwnd, GWL_STYLE, tmpWStyle )
  1048. Rethink()
  1049. SetWindowPos( _hwnd, Null, 0, 0, 0, 0, SWP_DRAWFRAME|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOOWNERZORDER|SWP_NOZORDER|SWP_NOSIZE )
  1050. EndIf
  1051. EndMethod
  1052. Method SetMaximumSize(w,h)
  1053. 'Set maximum size for current window style
  1054. _maxwidth=w;_maxheight=h
  1055. 'Get window style
  1056. Local tmpWStyle% = GetWindowLongW( _hwnd, GWL_STYLE )&~WS_MAXIMIZEBOX
  1057. 'Update size border
  1058. If (_maxwidth = _minwidth And _maxheight = _minheight) Then tmpWStyle:&~WS_SIZEBOX ElseIf (style&WINDOW_RESIZABLE) Then tmpWStyle:|WS_SIZEBOX
  1059. 'Set new window style if necessary
  1060. If tmpWStyle <> GetWindowLongW( _hwnd, GWL_STYLE ) Then
  1061. SetWindowLongW( _hwnd, GWL_STYLE, tmpWStyle )
  1062. Rethink()
  1063. SetWindowPos( _hwnd, Null, 0, 0, 0, 0, SWP_DRAWFRAME|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOOWNERZORDER|SWP_NOZORDER|SWP_NOSIZE )
  1064. EndIf
  1065. EndMethod
  1066. Method GetMenu:TGadget()
  1067. If Not _menu Then
  1068. _menu = New TWindowsMenu.Create(Null,0,"")
  1069. _menu._setParent Self
  1070. EndIf
  1071. Return _menu
  1072. EndMethod
  1073. Method UpdateMenu()
  1074. Local hmenu, oldMenu
  1075. If _menu
  1076. _menu.FreeKids
  1077. _menu.Open
  1078. hmenu=_menu._hmenu
  1079. EndIf
  1080. oldMenu = GetMenu_( _hwnd )
  1081. SetMenu _hwnd,hmenu
  1082. DrawMenuBar _hwnd
  1083. DestroyMenu oldMenu
  1084. EndMethod
  1085. Field _statustext$
  1086. Method GetStatusText$()
  1087. If _status
  1088. Return _statustext
  1089. EndIf
  1090. EndMethod
  1091. Method SetStatusText(Text$)
  1092. If _status
  1093. _statustext = Text
  1094. If (style&WINDOW_RESIZABLE) Then Text:+" " 'Cludge for size handle obfuscation
  1095. Local tmpWString:Short Ptr = Text.ToWString()
  1096. SendMessageW _status,WM_SETTEXT,0,Int(tmpWString)
  1097. MemFree tmpWString
  1098. EndIf
  1099. EndMethod
  1100. Field popupextra:Object
  1101. Method PopupMenu(menu:TGadget,extra:Object)
  1102. Local pt[2], wmenu:TWindowsMenu = TWindowsMenu(menu), tmpLink:TLink
  1103. If wmenu
  1104. GetCursorPos_ pt
  1105. popupextra = extra
  1106. wmenu.Open(True)
  1107. Local hmenu:Int = TrackPopupMenu( wmenu._hmenu,TPM_LEFTALIGN|TPM_TOPALIGN|TPM_RETURNCMD|TPM_NONOTIFY,pt[0],pt[1],0,_hwnd,0 )
  1108. If hmenu Then HandleMenuEvent( WM_COMMAND, hmenu )
  1109. wmenu.Close()
  1110. popupextra = Null
  1111. EndIf
  1112. EndMethod
  1113. Function EnumChildProc(hwnd,lp) "win32"
  1114. Local winfo:WINDOWINFO = New WINDOWINFO
  1115. winfo.cbSize=SizeOf winfo
  1116. GetWindowInfo hwnd,winfo
  1117. If winfo.dwStyle&WS_TABSTOP
  1118. _firsttab=hwnd
  1119. Else
  1120. EnumChildWindows hwnd,EnumChildProc,0
  1121. EndIf
  1122. If _firsttab Return 0
  1123. Return 1
  1124. EndFunction
  1125. Global _firsttab
  1126. Method Activate(cmd)
  1127. Select cmd
  1128. Case ACTIVATE_FOCUS
  1129. _firsttab=0
  1130. EnumChildWindows _hwnd,EnumChildProc,0
  1131. If Not _firsttab _firsttab=_hwnd
  1132. SetFocus _firsttab
  1133. Case ACTIVATE_MINIMIZE
  1134. ShowWindow _hwnd,SW_MINIMIZE
  1135. Case ACTIVATE_MAXIMIZE
  1136. ShowWindow _hwnd,SW_MAXIMIZE
  1137. Case ACTIVATE_RESTORE
  1138. ShowWindow _hwnd,SW_RESTORE
  1139. Case ACTIVATE_REDRAW
  1140. RefreshLook()
  1141. Return RedrawWindow( _hwnd, Null, Null, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN )
  1142. End Select
  1143. EndMethod
  1144. Method OnCommand(msg,wp)
  1145. If wp>100 Then HandleMenuEvent(msg,wp)
  1146. EndMethod
  1147. Method HandleMenuEvent( msg, wp )
  1148. Local tmpMenuSource:TWindowsMenu = TWindowsMenu.GetMenuFromKey(wp), tmpMenuID
  1149. If tmpMenuSource Then tmpMenuID = tmpMenuSource._tag
  1150. Local tmpPopupExtra:Object = popupextra
  1151. popupextra = Null
  1152. MaxGUI.MaxGUI.PostGuiEvent EVENT_MENUACTION,tmpMenuSource,tmpMenuID,0,0,0,tmpPopupExtra
  1153. EndMethod
  1154. Method WndProc(hwnd,msg,wp,lp)
  1155. Local x,y,w,h
  1156. Local move,size
  1157. Local Rect[4]
  1158. Local winrect[4]
  1159. Select msg
  1160. Case WM_ERASEBKGND
  1161. If BgBrush() Then
  1162. Local Rect[4]
  1163. If Not GetUpdateRect( hwnd, Rect, False ) Then GetClipBox( wp, Rect )
  1164. FillRect( wp, Rect, BgBrush() )
  1165. Return 1
  1166. EndIf
  1167. Case WM_SIZE
  1168. If (hwnd = _hwnd) And (wp <> SIZE_MINIMIZED) Then
  1169. If _status Then SendMessageW _status,WM_SIZE,0,0
  1170. If (style & WINDOW_CLIENTCOORDS) Then
  1171. GetClientRect _hwnd,Rect
  1172. w=Rect[2]
  1173. h=Rect[3]
  1174. AdjustWindowRectEx(Rect,GetWindowLongW(_hwnd, GWL_STYLE),_hmenu,GetWindowLongW(_hwnd, GWL_EXSTYLE))
  1175. x=-Rect[0]
  1176. y=-Rect[1]
  1177. GetWindowRect _hwnd,Rect
  1178. x:+Rect[0]
  1179. y:+Rect[1]
  1180. If _status Then
  1181. GetWindowRect _status,Rect
  1182. h:-(Rect[3]-Rect[1])
  1183. EndIf
  1184. x:+_clientX;y:+_clientY
  1185. w:-_clientX;h:-_clientY
  1186. Else
  1187. GetWindowRect(_hwnd,Rect)
  1188. x=Rect[0];y=Rect[1]
  1189. w=Rect[2]-Rect[0]
  1190. h=Rect[3]-Rect[1]
  1191. EndIf
  1192. If x<>xpos Or y<>ypos Then move = True
  1193. If w<>width Or h<>height Then size = True
  1194. SetRect x,y,w,h
  1195. If size Then RethinkClient()
  1196. If move PostGuiEvent EVENT_WINDOWMOVE,0,0,x,y
  1197. If size PostGuiEvent EVENT_WINDOWSIZE,0,0,w,h
  1198. EndIf
  1199. Case WM_MOVE
  1200. If (hwnd = _hwnd) And Not (IsZoomed(hwnd) Or IsIconic(hwnd)) Then
  1201. If (style & WINDOW_CLIENTCOORDS) Then
  1202. GetClientRect _hwnd,Rect
  1203. w=Rect[2]
  1204. h=Rect[3]
  1205. AdjustWindowRectEx(Rect,GetWindowLongW(_hwnd, GWL_STYLE),_hmenu,GetWindowLongW(_hwnd, GWL_EXSTYLE))
  1206. x=-Rect[0]
  1207. y=-Rect[1]
  1208. GetWindowRect _hwnd,Rect
  1209. x:+Rect[0]+_clientX
  1210. y:+Rect[1]+_clientY
  1211. Else
  1212. GetWindowRect(_hwnd,Rect)
  1213. x=Rect[0];y=Rect[1]
  1214. w=Rect[2]-Rect[0]
  1215. h=Rect[3]-Rect[1]
  1216. EndIf
  1217. If x<>xpos Or y<>ypos Then
  1218. SetRect x,y,width,height
  1219. PostGuiEvent EVENT_WINDOWMOVE,0,0,x,y
  1220. EndIf
  1221. EndIf
  1222. Case WM_GETMINMAXINFO
  1223. If hwnd = _hwnd And lp Then
  1224. Local minmax:Int Ptr = Int Ptr(lp), tmpZero% = 0
  1225. minmax[6]=_minwidth
  1226. minmax[7]=_minheight
  1227. ConvertToContainerDimensions(tmpZero,tmpZero,minmax[6],minmax[7])
  1228. If (_maxwidth >= _minwidth) And (_maxheight >= _minheight) Then
  1229. minmax[8]=_maxwidth
  1230. minmax[9]=_maxheight
  1231. ConvertToContainerDimensions(tmpZero,tmpZero,minmax[8],minmax[9])
  1232. EndIf
  1233. EndIf
  1234. Case WM_ACTIVATE
  1235. If (wp = WA_ACTIVE) Or (wp = WA_CLICKACTIVE) Then
  1236. TWindowsGUIDriver._ActiveWindow = Self
  1237. PostGuiEvent EVENT_WINDOWACTIVATE
  1238. EndIf
  1239. Case WM_COMMAND
  1240. If wp>100 Then HandleMenuEvent(wp,msg)
  1241. Case WM_CLOSE
  1242. PostGuiEvent EVENT_WINDOWCLOSE
  1243. Return 1
  1244. Case WM_DROPFILES
  1245. Local hdrop,pt[2],path$
  1246. Local pbuffer:Short[MAX_PATH]
  1247. Local i,n,l
  1248. DragQueryPoint wp,pt
  1249. n=DragQueryFileW(wp,$ffffffff,Null,0);
  1250. For i=0 Until n
  1251. l=DragQueryFileW(wp,i,pbuffer,MAX_PATH)
  1252. path=String.FromShorts(pbuffer,l)
  1253. PostGuiEvent EVENT_WINDOWACCEPT,0,0,pt[0],pt[1],path
  1254. Next
  1255. DragFinish wp
  1256. End Select
  1257. Return Super.WndProc(hwnd,msg,wp,lp)
  1258. EndMethod
  1259. Method DoLayout()
  1260. 'Don't do anything!
  1261. EndMethod
  1262. Method SetTooltip( pTooltip$ )
  1263. 'Windows shouldn't have tool-tips!
  1264. EndMethod
  1265. Method SetSensitivity(flags)
  1266. 'Problems with resizing/moving sensitive windows.
  1267. Super.SetSensitivity(flags&~SENSITIZE_MOUSE)
  1268. 'Easy to create an active panel in client area as a work around.
  1269. EndMethod
  1270. Method SetPixmap(pPixmap:TPixmap, pFlags)
  1271. If Not (pFlags & GADGETPIXMAP_ICON) Then Return False
  1272. If _iconBitmap Then DestroyIcon(_iconBitmap);_iconBitmap = 0
  1273. If pPixmap Then _iconBitmap = TWindowsGraphic.IconFromPixmap32( pPixmap )
  1274. SendMessageW (_hwnd, WM_SETICON, 0, _iconBitmap)
  1275. SendMessageW (_hwnd, WM_SETICON, 1, _iconBitmap)
  1276. Return True
  1277. EndMethod
  1278. ' Needed otherwise SetEnabled() locks if modal child window is opened and parent is disabled.
  1279. Method isControl()
  1280. Return False
  1281. EndMethod
  1282. Method ConvertToContainerDimensions%( pX Var, pY Var, pW Var , pH Var )
  1283. If Not (style & WINDOW_CLIENTCOORDS) Then Return 0
  1284. Local Rect[4], menu = GetMenu_(_hwnd)
  1285. If menu Then menu = True
  1286. If _status Then GetWindowRect _status,Rect;pH:+(Rect[3]-Rect[1])
  1287. pW:+_clientX;pH:+_clientY;pX:-_clientX;pY:-_clientY
  1288. Rect = [pX,pY,pX+pW,pY+pH]
  1289. AdjustWindowRectEx Rect,GetWindowLongW(_hwnd, GWL_STYLE),menu,GetWindowLongW(_hwnd, GWL_EXSTYLE)
  1290. pX = Rect[0];pY = Rect[1];pW = Rect[2]-Rect[0];pH = Rect[3]-Rect[1]
  1291. Return 1
  1292. EndMethod
  1293. Method FlushBrushes(pRecurse:Int = True)
  1294. Super.FlushBrushes()
  1295. If Not pRecurse Then Return
  1296. For Local tmpGadget:TWindowsGadget = EachIn kids
  1297. tmpGadget.FlushBrushes()
  1298. Next
  1299. EndMethod
  1300. EndType
  1301. Type TWindowsButton Extends TWindowsGadget
  1302. Field _buttonImageList[] = [-1,0,0,0,0,0], _strButtonText$, _mouseoverbutton
  1303. Method Create:TWindowsGadget(group:TGadget,style,Text$="")
  1304. Local xstyle,wstyle,hotkey
  1305. Local hwnd,parent
  1306. Self.style = style
  1307. wstyle=WS_CHILD|WS_TABSTOP|WS_CLIPSIBLINGS|BS_MULTILINE
  1308. Select style&7
  1309. Case 0 wstyle:|BS_PUSHBUTTON;style = BUTTON_PUSH
  1310. Case BUTTON_CHECKBOX wstyle:|BS_3STATE;If (style&BUTTON_PUSH) Then wstyle:|BS_PUSHLIKE
  1311. Case BUTTON_RADIO wstyle:|BS_AUTORADIOBUTTON;If (style&BUTTON_PUSH) Then wstyle:|BS_PUSHLIKE
  1312. Case BUTTON_OK wstyle:|BS_DEFPUSHBUTTON;hotkey=IDOK
  1313. Case BUTTON_CANCEL wstyle:|BS_PUSHBUTTON;hotkey=IDCANCEL
  1314. End Select
  1315. parent=group.query(QUERY_HWND_CLIENT)
  1316. hwnd=CreateWindowExW(xstyle,"BUTTON","",wstyle,0,0,0,0,parent,hotkey,GetModuleHandleW(Null),Null)
  1317. Register GADGET_BUTTON,hwnd
  1318. Return Self
  1319. EndMethod
  1320. Method SetTextColor(r,g,b)
  1321. If Not (style&7) Then
  1322. SetWindowLongW(_hwnd,GWL_STYLE,GetWindowLongW(_hwnd,GWL_STYLE)|BS_OWNERDRAW)
  1323. If Not _hTheme Then _hTheme = TWindowsGUIDriver.GetThemeHandle( _hwnd, "Button" )
  1324. ElseIf Not (style&BUTTON_PUSH) And ((style&7=BUTTON_CHECKBOX) Or (style&7=BUTTON_RADIO))
  1325. If SetWindowThemeW Then SetWindowThemeW(_hwnd,_wstrSpace,_wstrSpace)
  1326. EndIf
  1327. Super.SetTextColor(r,g,b)
  1328. EndMethod
  1329. Method SetColor(r,g,b)
  1330. If Not (style&7) Then
  1331. SetWindowLongW(_hwnd,GWL_STYLE,GetWindowLongW(_hwnd,GWL_STYLE)|BS_OWNERDRAW)
  1332. If Not _hTheme Then _hTheme = TWindowsGUIDriver.GetThemeHandle( _hwnd, "Button" )
  1333. EndIf
  1334. Super.SetColor(r,g,b)
  1335. EndMethod
  1336. Method RemoveColor()
  1337. If Not (style&7) Then
  1338. SetWindowLongW(_hwnd,GWL_STYLE,GetWindowLongW(_hwnd,GWL_STYLE)&~BS_OWNERDRAW)
  1339. _hTheme=0
  1340. EndIf
  1341. Super.RemoveColor()
  1342. EndMethod
  1343. Method State()
  1344. Local t=Super.State()
  1345. Select SendMessageW( _hwnd,BM_GETCHECK,0,0 )
  1346. Case BST_CHECKED;t:|STATE_SELECTED
  1347. Case BST_INDETERMINATE;t:|STATE_INDETERMINATE
  1348. EndSelect
  1349. Return t
  1350. EndMethod
  1351. Method SetSelected(bool)
  1352. Local state = BST_UNCHECKED
  1353. If bool Then
  1354. If (style&7 = BUTTON_CHECKBOX) And (bool = CHECK_INDETERMINATE) Then
  1355. state = BST_INDETERMINATE
  1356. Else
  1357. state = BST_CHECKED
  1358. EndIf
  1359. EndIf
  1360. SendMessageW _hwnd,BM_SETCHECK,state,0
  1361. EndMethod
  1362. Method WndProc(hwnd,msg,wp,lp)
  1363. Select msg
  1364. Case WM_THEMECHANGED
  1365. If _hTheme Then
  1366. TWindowsGUIDriver.CloseThemeHandle(_hTheme)
  1367. _hTheme = TWindowsGUIDriver.GetThemeHandle(_hwnd,"BUTTON")
  1368. EndIf
  1369. Case WM_LBUTTONDBLCLK
  1370. PostMessageW(_hwnd, WM_LBUTTONDOWN, wp, lp)
  1371. Case WM_MOUSEMOVE
  1372. If Not _mouseoverbutton Then
  1373. _mouseoverbutton = True
  1374. InvalidateRect(_hwnd,Null,False)
  1375. Local tmpTrackMouseEvent:Int[] = [ 16, $2, hwnd, 0 ] 'TME_LEAVE: $2
  1376. _TrackMouseEvent( tmpTrackMouseEvent )
  1377. EndIf
  1378. Case WM_MOUSELEAVE
  1379. If _mouseoverbutton Then
  1380. _mouseoverbutton = False
  1381. InvalidateRect(_hwnd,Null,False)
  1382. EndIf
  1383. Case WM_ERASEBKGND
  1384. Return 1
  1385. EndSelect
  1386. Return Super.WndProc(hwnd,msg,wp,lp)
  1387. EndMethod
  1388. Method OnDrawItem(pDrawItemStruct:DRAWITEMSTRUCT)
  1389. Local tmpDc = pDrawItemStruct.hDc, txtWidth%, txtHeight%
  1390. Local tmpDcState = SaveDC(tmpDC)
  1391. ' button state
  1392. Local tmpIsPressed = (pDrawItemStruct.ItemState & ODS_SELECTED)
  1393. Local tmpIsFocused = (pDrawItemStruct.ItemState & ODS_FOCUS)
  1394. Local tmpIsDisabled = (pDrawItemStruct.ItemState & ODS_DISABLED)
  1395. Local tmpDrawFocusRect = Not (pDrawItemStruct.ItemState & ODS_NOFOCUSRECT)
  1396. Local itemRect:Int Ptr = Int Ptr Varptr pDrawItemStruct.rcItem_left, txtRect:Int[4], clientRect:Int[4]
  1397. Local tmpBgMode = SetBkMode(tmpDc, TRANSPARENT)
  1398. ' Prepare draw... paint button background
  1399. If _hTheme Then
  1400. Local tmpState = PBS_NORMAL
  1401. If tmpIsDisabled Then
  1402. tmpState = PBS_DISABLED
  1403. ElseIf tmpIsPressed Then
  1404. tmpState = PBS_PRESSED
  1405. ElseIf _mouseoverbutton Then
  1406. tmpState = PBS_HOT
  1407. ElseIf tmpIsFocused Then
  1408. tmpState = PBS_DEFAULTED
  1409. EndIf
  1410. If IsThemeBackgroundPartiallyTransparent(_hTheme, BP_PUSHBUTTON, tmpState) Then
  1411. DrawThemeParentBackground( _hwnd, tmpDc, itemRect )
  1412. EndIf
  1413. DrawThemeBackground(_hTheme, tmpDc, BP_PUSHBUTTON, tmpState, itemRect, Null)
  1414. GetThemeBackgroundContentRect(_hTheme, tmpDc, BP_PUSHBUTTON, tmpState, itemRect, clientRect)
  1415. Else
  1416. clientRect = [itemRect[0], itemRect[1], itemRect[2], itemRect[3]]
  1417. InflateRect(clientRect, -GetSystemMetrics(SM_CXEDGE), -GetSystemMetrics(SM_CYEDGE))
  1418. If tmpIsFocused Then
  1419. Local tmpBr = CreateSolidBrush($000000)
  1420. FrameRect(tmpDc, itemRect , tmpBr)
  1421. InflateRect(itemRect, -1, -1)
  1422. DeleteObject(tmpBr)
  1423. EndIf
  1424. Local crColor
  1425. If BgColor() < 0 Then crColor = GetSysColor(COLOR_BTNFACE) Else crColor = BgColor()
  1426. Local brBackground = CreateSolidBrush(crColor)
  1427. FillRect(tmpDc, itemRect, brBackground)
  1428. DeleteObject(brBackground)
  1429. ' Draw pressed button
  1430. If tmpIsPressed
  1431. Local brBtnShadow = CreateSolidBrush(GetSysColor(COLOR_BTNSHADOW))
  1432. FrameRect(tmpDc, itemRect, brBtnShadow)
  1433. DeleteObject(brBtnShadow)
  1434. OffsetRect( clientRect, 1, 1 )
  1435. Else ' ...Else draw non pressed button
  1436. Local tmpUState = DFCS_BUTTONPUSH
  1437. If _mouseoverbutton Then tmpUState :| DFCS_HOT
  1438. If tmpIsPressed Then tmpUState :| DFCS_PUSHED
  1439. DrawFrameControl(tmpDc, itemRect, DFC_BUTTON, tmpUState)
  1440. EndIf
  1441. EndIf
  1442. If BgColor() > -1 Then
  1443. Local brBackground = CreateSolidBrush(BgColor())
  1444. FillRect(tmpDc, clientRect, brBackground)
  1445. DeleteObject(brBackground)
  1446. EndIf
  1447. txtRect = clientRect[..]
  1448. clientRect[RECT_RIGHT]:-clientRect[RECT_LEFT]
  1449. clientRect[RECT_BOTTOM]:-clientRect[RECT_TOP]
  1450. ' Read the button's title
  1451. Local tmpText$ = Super.GetText()
  1452. ' Draw the icon
  1453. 'DrawTheIcon(GetDlgItem(hDlg, IDC_OWNERDRAW_BTN), &dc, bHasTitle, &lpDIS.rcItem, &captionRect, bIsPressed, bIsDisabled)
  1454. ' Write the button title (if any)
  1455. If tmpText Then
  1456. Local tmpFlags = DT_CENTER|DT_WORDBREAK
  1457. DrawTextW( tmpDc, tmpText, -1, txtRect, DT_CALCRECT|tmpFlags )
  1458. txtWidth = txtRect[RECT_RIGHT]-txtRect[RECT_LEFT]
  1459. txtHeight = txtRect[RECT_BOTTOM]-txtRect[RECT_TOP]
  1460. txtRect[RECT_LEFT] = clientRect[RECT_LEFT] + (clientRect[RECT_RIGHT] - txtWidth)/2
  1461. txtRect[RECT_TOP] = clientRect[RECT_TOP] + (clientRect[RECT_BOTTOM] - txtHeight)/2
  1462. txtRect[RECT_RIGHT] = txtRect[RECT_LEFT] + txtWidth
  1463. txtRect[RECT_BOTTOM] = txtRect[RECT_TOP] + txtHeight
  1464. Local tmpTextColor
  1465. If tmpIsDisabled Then
  1466. tmpTextColor = GetSysColor(COLOR_GRAYTEXT)
  1467. Else
  1468. If FgColor() < 0 Then tmpTextColor = GetSysColor(COLOR_BTNTEXT) Else tmpTextColor = FgColor()
  1469. EndIf
  1470. tmpTextColor = SetTextColor_(tmpDc,tmpTextColor)
  1471. DrawTextW( tmpDc, tmpText, -1, txtRect, tmpFlags )
  1472. SetTextColor_(tmpDc,tmpTextColor)
  1473. EndIf
  1474. RestoreDC(tmpDc,tmpDcState)
  1475. ' Draw the focus rect
  1476. If tmpIsFocused And tmpDrawFocusRect Then
  1477. Local focusRect:Int[4]
  1478. CopyRect(focusRect, itemRect)
  1479. InflateRect(focusRect, -3, -3)
  1480. SetMapMode(tmpDc, MM_TEXT)
  1481. DrawFocusRect(tmpDc, focusRect)
  1482. EndIf
  1483. Return True
  1484. EndMethod
  1485. Method OnCommand(msg,wp)
  1486. Select wp Shr 16
  1487. Case BN_CLICKED
  1488. Select (style&7)
  1489. Case BUTTON_CHECKBOX
  1490. Select State()&STATE_INDETERMINATE
  1491. Case 0, STATE_INDETERMINATE
  1492. SetSelected(True)
  1493. Case STATE_SELECTED
  1494. SetSelected(False)
  1495. EndSelect
  1496. EndSelect
  1497. PostGuiEvent EVENT_GADGETACTION,ButtonState(Self)
  1498. 'Fix so that tooltips reappear on Windows XP
  1499. Local tmpTooltip$ = GetTooltip()
  1500. If tmpTooltip Then SetTooltip("");SetTooltip(tmpTooltip)
  1501. EndSelect
  1502. EndMethod
  1503. Method SetPixmap(pixmap:TPixmap,pFlags)
  1504. Local tmpWindowStyle = GetWindowLongW(_hwnd,GWL_STYLE)
  1505. If (pFlags & GADGETPIXMAP_ICON) And (((style&BUTTON_PUSH)=BUTTON_PUSH) Or (style = BUTTON_CANCEL)) Then
  1506. 'To remove an image from a button, a handle-list of -1 should be passed.
  1507. If _buttonImageList[0] >= 0 Then ImageList_Destroy(_buttonImageList[0]);_buttonImageList[0] = -1
  1508. If pixmap Then _buttonImageList[0] = BuildImageList( pixmap )
  1509. If (pFlags & GADGETPIXMAP_NOTEXT) Then
  1510. _buttonImageList[5] = BUTTON_IMAGELIST_ALIGN_CENTER
  1511. Else
  1512. _buttonImageList[5] = BUTTON_IMAGELIST_ALIGN_LEFT
  1513. EndIf
  1514. 'If running Windows XP/Vista, let's use BCM_SETIMAGELIST
  1515. If Not SendMessageW (_hwnd, BCM_SETIMAGELIST, 0, Int Byte Ptr _buttonImageList) Then
  1516. 'Otherwise, if this fails we should use BM_SETIMAGE.
  1517. If _buttonImageList[0] >= 0 Then ImageList_Destroy(_buttonImageList[0]);_buttonImageList[0] = -1
  1518. If _iconBitmap Then DeleteObject(_iconBitmap);_iconBitmap = 0
  1519. If pixmap Then _iconBitmap = TWindowsGraphic.BitmapFromPixmap( pixmap, True )
  1520. SendMessageW (_hwnd, BM_SETIMAGE, IMAGE_BITMAP, _iconBitmap)
  1521. EndIf
  1522. 'Show the text if there isn't a pixmap or if we haven't specified GADGETPIXMAP_NOTEXT.
  1523. If (Not pixmap) Or Not(pFlags & GADGETPIXMAP_NOTEXT) Then
  1524. tmpWindowStyle:&(~BS_BITMAP)
  1525. 'Text isn't hidden on XP image buttons regardless of whether BS_BITMAP is set
  1526. 'so we have to hack this in - they must have fixed it on Vista though as it works fine there.
  1527. Super.SetText( GetText() )
  1528. Else
  1529. tmpWindowStyle:|BS_BITMAP
  1530. 'Text isn't hidden on XP image buttons regardless of whether BS_BITMAP is set
  1531. 'so we have to hack this in - they must have fixed it on Vista though as it works fine there.
  1532. Super.SetText( "" )
  1533. EndIf
  1534. SetWindowLongW _hwnd,GWL_STYLE,tmpWindowStyle
  1535. InvalidateRect _hwnd, Null, False
  1536. Return True
  1537. EndIf
  1538. EndMethod
  1539. Method SetText(pText$)
  1540. Local oldText$ = _strButtonText
  1541. _strButtonText = pText
  1542. If (_buttonImageList[0] < 0 And Not _iconBitmap) Or (oldText = Super.GetText()) Then Super.SetText(pText)
  1543. EndMethod
  1544. Method GetText$()
  1545. Return _strButtonText
  1546. EndMethod
  1547. Method Free()
  1548. If _buttonImageList[0] >= 0 Then ImageList_Destroy(_buttonImageList[0])
  1549. If _iconBitmap Then DestroyIcon( _iconBitmap );_iconBitmap = 0
  1550. _buttonImageList = Null
  1551. Super.Free()
  1552. EndMethod
  1553. Function BuildImageList(pixmap:TPixmap)
  1554. Local bitmap,imagelist,mask
  1555. If TWindowsGUIDriver.CheckCommonControlVersion() And (Pixmap.format=PF_RGBA8888 Or pixmap.format=PF_BGRA8888)
  1556. imagelist=ImageList_Create(pixmap.width,pixmap.height,ILC_COLOR32,0,1)
  1557. If imagelist
  1558. bitmap=TWindowsGraphic.BitmapFromPixmap(pixmap, True)
  1559. ImageList_Add(imagelist,bitmap,0)
  1560. EndIf
  1561. EndIf
  1562. If imagelist=0
  1563. bitmap=TWindowsGraphic.BitmapFromPixmap(pixmap, False)
  1564. mask=TWindowsGraphic.BitmapMaskFromPixmap(pixmap)
  1565. imagelist=ImageList_Create(pixmap.width,pixmap.height,ILC_COLOR24|ILC_MASK,0,1)
  1566. ImageList_Add(imagelist,bitmap,mask)
  1567. DeleteObject(mask)
  1568. EndIf
  1569. DeleteObject(bitmap)
  1570. Return imagelist
  1571. EndFunction
  1572. Method Class()
  1573. Return GADGET_BUTTON
  1574. EndMethod
  1575. EndType
  1576. Type TWindowsTextField Extends TWindowsGadget
  1577. Field _busy
  1578. Method Create:TWindowsGadget(group:TGadget,style,Text$="")
  1579. Local xstyle,wstyle,hotkey
  1580. Local hwnd,parent
  1581. Self.style = style
  1582. xstyle=WS_EX_CLIENTEDGE
  1583. wstyle=WS_CHILD|WS_TABSTOP|ES_AUTOHSCROLL|WS_CLIPSIBLINGS
  1584. If style&TEXTFIELD_PASSWORD Then wstyle:|ES_PASSWORD
  1585. parent=group.query(QUERY_HWND_CLIENT)
  1586. hwnd=CreateWindowExW(xstyle,"EDIT","",wstyle,0,0,0,0,parent,hotkey,GetModuleHandleW(Null),Null)
  1587. 'SendMessageW hwnd,WM_SETFONT,TWindowsGUIDriver.GDIFont.handle,1
  1588. Register GADGET_TEXTFIELD,hwnd
  1589. SetColor(255,255,255)
  1590. Return Self
  1591. EndMethod
  1592. Method SetText(Text$)
  1593. Local p0,p1
  1594. _busy:+1
  1595. SendMessageW _hwnd,EM_GETSEL,Int Byte Ptr Varptr p0,Int Byte Ptr Varptr p1
  1596. Super.SetText(Text)
  1597. SendMessageW _hwnd,EM_SETSEL,p0,p1
  1598. _busy:-1
  1599. EndMethod
  1600. Method Activate(cmd)
  1601. Select cmd
  1602. Case ACTIVATE_CUT
  1603. SendMessageW _hwnd,WM_CUT,0,0
  1604. Case ACTIVATE_COPY
  1605. SendMessageW _hwnd,WM_COPY,0,0
  1606. Case ACTIVATE_PASTE
  1607. SendMessageW _hwnd,WM_PASTE,0,0
  1608. Case ACTIVATE_FOCUS
  1609. SendMessageW _hwnd,EM_SETSEL,0,-1
  1610. End Select
  1611. Return Super.Activate(cmd)
  1612. EndMethod
  1613. Method OnCommand(msg,wp)
  1614. If Not _busy
  1615. Select (wp Shr 16)
  1616. Case EN_UPDATE
  1617. PostGuiEvent EVENT_GADGETACTION
  1618. Case EN_KILLFOCUS
  1619. SendMessageW _hwnd,EM_SETSEL,0,0
  1620. End Select
  1621. EndIf
  1622. EndMethod
  1623. Method WndProc(hwnd,msg,wp,lp)
  1624. Local event:TEvent
  1625. Select msg
  1626. Case WM_ERASEBKGND
  1627. Return 1
  1628. Case WM_KEYDOWN
  1629. If eventfilter<>Null
  1630. event=CreateEvent(EVENT_KEYDOWN,Self,wp,keymods())
  1631. If Not eventfilter(event,context) Return True
  1632. EndIf
  1633. Case WM_CHAR
  1634. If eventfilter<>Null
  1635. event=CreateEvent(EVENT_KEYCHAR,Self,wp,keymods())
  1636. If Not eventfilter(event,context) Return True
  1637. EndIf
  1638. Case WM_KILLFOCUS
  1639. PostGuiEvent EVENT_GADGETLOSTFOCUS
  1640. End Select
  1641. Return Super.WndProc(hwnd,msg,wp,lp)
  1642. EndMethod
  1643. Method Class()
  1644. Return GADGET_TEXTFIELD
  1645. EndMethod
  1646. EndType
  1647. Type TWindowsTextArea Extends TWindowsGadget
  1648. Global _ClassName:String = Null 'See InitializeLibrary().
  1649. Global _pagemargin# = 0.5 'Page margin for print-out in inches
  1650. Field _locked
  1651. Field cr1:CHARRANGE=New CHARRANGE
  1652. Field cr2:CHARRANGE=New CHARRANGE
  1653. Field cf:CHARFORMATW=New CHARFORMATW
  1654. Field ole:IRichEditOLE
  1655. Field idoc:ITextDocument
  1656. Field busy,readonly
  1657. Field IID_ITextDocument:GUID = New GUID
  1658. Function _InitializeLibrary()
  1659. If Not _ClassName Then
  1660. 'Load RichEdit DLL
  1661. If Not LoadLibraryW("msftedit.dll") Then
  1662. If LoadLibraryW("riched20.dll") _ClassName = "RichEdit20W"
  1663. Else
  1664. _ClassName = "RICHEDIT50W"
  1665. EndIf
  1666. EndIf
  1667. EndFunction
  1668. Method New()
  1669. _InitializeLibrary()
  1670. EndMethod
  1671. Method Create:TWindowsGadget(group:TGadget,style,Text$="")
  1672. Local xstyle,wstyle,hotkey
  1673. Local hwnd,parent
  1674. Local res
  1675. xstyle=WS_EX_CLIENTEDGE
  1676. wstyle=WS_CHILD|WS_VSCROLL|WS_CLIPSIBLINGS
  1677. wstyle:|ES_MULTILINE|ES_NOOLEDRAGDROP|ES_NOHIDESEL|ES_LEFT
  1678. If Not (style&TEXTAREA_WORDWRAP) wstyle:|WS_HSCROLL|ES_AUTOHSCROLL
  1679. ' If (style&TEXTAREA_READONLY) wstyle:|ES_READONLY
  1680. If (style&TEXTAREA_READONLY) readonly=True
  1681. Self.style = style
  1682. parent=group.query(QUERY_HWND_CLIENT)
  1683. 'RichText control should be made have dimensions of 1x1 pixels to fix Windows XP vertical scrollbar drawing bug.
  1684. hwnd=CreateWindowExW(xstyle,_ClassName,"",wstyle,0,0,1,1,parent,hotkey,GetModuleHandleW(Null),Null)
  1685. SendMessageW hwnd,EM_SETLIMITTEXT,4*1024*1024,0
  1686. SendMessageW hwnd,EM_SETEVENTMASK,0,ENM_CHANGE|ENM_MOUSEEVENTS|ENM_SELCHANGE|ENM_KEYEVENTS
  1687. SendMessageW hwnd,EM_SETUNDOLIMIT,0,0
  1688. SendMessageW hwnd,EM_GETOLEINTERFACE,0,Int Byte Ptr Varptr ole
  1689. res=IIDFromString(ITextDocument_UUID,IID_ITextDocument)
  1690. res=ole.QueryInterface(IID_ITextDocument,Varptr idoc)
  1691. Register GADGET_TEXTAREA,hwnd
  1692. Return Self
  1693. EndMethod
  1694. Method Free()
  1695. If ole Then ole.Release_
  1696. If idoc Then idoc.Release_
  1697. Super.Free()
  1698. EndMethod
  1699. Method Activate(cmd)
  1700. Select cmd
  1701. Case ACTIVATE_CUT
  1702. SendMessageW _hwnd,WM_CUT,0,0
  1703. Case ACTIVATE_COPY
  1704. SendMessageW _hwnd,WM_COPY,0,0
  1705. SetFocus _hwnd
  1706. Case ACTIVATE_PASTE
  1707. DoPaste
  1708. Case ACTIVATE_PRINT
  1709. DoPrint
  1710. Default
  1711. Return Super.Activate(cmd)
  1712. End Select
  1713. EndMethod
  1714. Method DoPaste()
  1715. Local h,handle,n
  1716. Local w:Short Ptr,cp:Short Ptr
  1717. Local tp:Byte Ptr,bp:Byte Ptr
  1718. If OpenClipboard(_hwnd)
  1719. If IsClipboardFormatAvailable(CF_UNICODETEXT)
  1720. handle=GetClipboardData(CF_UNICODETEXT)
  1721. n=GlobalSize(handle)
  1722. w=Short Ptr GlobalLock(handle)
  1723. h=GlobalAlloc(GMEM_MOVEABLE,n)
  1724. cp=Short Ptr GlobalLock(h)
  1725. memcpy_(cp,w,n)
  1726. If cp[n/2-2]=10 Then cp[n/2-2]=13
  1727. GlobalUnlock h
  1728. GlobalUnlock handle
  1729. If h
  1730. EmptyClipboard
  1731. SetClipboardData CF_UNICODETEXT,h
  1732. EndIf
  1733. ElseIf IsClipboardFormatAvailable(CF_OEMTEXT)
  1734. handle=GetClipboardData(CF_OEMTEXT)
  1735. n=GlobalSize(handle)
  1736. tp=Byte Ptr GlobalLock(handle)
  1737. h=GlobalAlloc(GMEM_MOVEABLE,n)
  1738. bp=Byte Ptr GlobalLock(h)
  1739. memcpy_(bp,tp,n)
  1740. If bp[n-2]=10 Then bp[n-2]=13
  1741. GlobalUnlock h
  1742. GlobalUnlock handle
  1743. If h
  1744. EmptyClipboard
  1745. SetClipboardData CF_OEMTEXT,h
  1746. EndIf
  1747. EndIf
  1748. CloseClipboard
  1749. SendMessageW _hwnd,WM_PASTE,0,0
  1750. SetFocus _hwnd
  1751. EndIf
  1752. EndMethod
  1753. Method DoPrint()
  1754. Local tmpTextSelLen = TextAreaSelLen(Self)
  1755. Local tmpPrintDialog:PRINTDLGW = New PRINTDLGW
  1756. tmpPrintDialog.flags = PD_RETURNDC | PD_HIDEPRINTTOFILE | PD_NOPAGENUMS
  1757. If Not tmpTextSelLen Then tmpPrintDialog.flags:|PD_NOSELECTION
  1758. tmpPrintDialog.hwndOwner = _hwnd
  1759. If Not PrintDlg( Byte Ptr tmpPrintDialog ) Then Return 0
  1760. Local hdcPrinter = tmpPrintDialog.hdc
  1761. Local tmpDoc:DOCINFOW = New DOCINFOW
  1762. Local tmpDocTitle:Short Ptr = AppTitle.ToWString()
  1763. tmpDoc.lpszDocName = tmpDocTitle
  1764. Local tmpSuccess = (StartDocW( hdcPrinter, Byte Ptr tmpDoc ) > 0)
  1765. If tmpSuccess Then
  1766. Local _cursor = TWindowsGUIDriver._cursor
  1767. SetPointer( POINTER_WAIT )
  1768. SetMapMode( hdcPrinter, MM_TEXT )
  1769. Local wPage = GetDeviceCaps( hdcPrinter, PHYSICALWIDTH )
  1770. Local hPage = GetDeviceCaps( hdcPrinter, PHYSICALHEIGHT )
  1771. Local xPPI = GetDeviceCaps( hdcPrinter, LOGPIXELSX )
  1772. Local yPPI = GetDeviceCaps( hdcPrinter, LOGPIXELSY )
  1773. Local tmpTextLengthStruct[] = [GTL_DEFAULT,1200]
  1774. Local tmpTextLength = SendMessageW (_hwnd, EM_GETTEXTLENGTHEX, Int Byte Ptr tmpTextLengthStruct, 0)
  1775. Local tmpTextPrinted, tmpFormatRange:FORMATRANGE = New FORMATRANGE
  1776. tmpFormatRange.hdc = hdcPrinter
  1777. tmpFormatRange.hdcTarget = hdcPrinter
  1778. tmpFormatRange.rcPageRight = (wPage*1440:Long)/xPPI
  1779. tmpFormatRange.rcPageBottom = (hPage*1440:Long)/yPPI
  1780. tmpFormatRange.rcLeft = (1440*_pagemargin);tmpFormatRange.rcTop = (1440*_pagemargin)
  1781. tmpFormatRange.rcRight = tmpFormatRange.rcPageRight - (2880*_pagemargin)
  1782. tmpFormatRange.rcBottom = tmpFormatRange.rcPageBottom - (2880*_pagemargin)
  1783. If tmpPrintDialog.flags & PD_SELECTION Then
  1784. tmpTextPrinted = TextAreaCursor(Self)
  1785. tmpFormatRange.CHARRANGE_cpMax = tmpTextPrinted+tmpTextSelLen
  1786. Else
  1787. tmpFormatRange.CHARRANGE_cpMax = tmpTextLength
  1788. EndIf
  1789. SendMessageW (_hwnd, EM_FORMATRANGE, False, 0)
  1790. While tmpSuccess And ( tmpTextPrinted < tmpFormatRange.CHARRANGE_cpMax )
  1791. tmpFormatRange.CHARRANGE_cpMin = tmpTextPrinted
  1792. tmpSuccess = (StartPage(hdcPrinter) > 0)
  1793. If Not tmpSuccess Then Exit
  1794. tmpTextPrinted = SendMessageW( _hwnd, EM_FORMATRANGE, True, Int Byte Ptr tmpFormatRange )
  1795. tmpSuccess = (EndPage(hdcPrinter) > 0)
  1796. Wend
  1797. If tmpSuccess Then EndDoc( hdcPrinter ) Else AbortDoc( hdcPrinter )
  1798. SendMessageW (_hwnd, EM_FORMATRANGE, False, 0)
  1799. TWindowsGUIDriver._cursor = _cursor
  1800. SetCursor _cursor
  1801. EndIf
  1802. GlobalFree( tmpPrintDialog.hDevMode )
  1803. GlobalFree( tmpPrintDialog.hDevNames )
  1804. DeleteDC( hdcPrinter )
  1805. MemFree tmpDocTitle
  1806. Return tmpSuccess
  1807. EndMethod
  1808. Global gt[] = [GTL_DEFAULT, CP_ACP]
  1809. Method CharCount()
  1810. Return SendMessageW(_hwnd,EM_GETTEXTLENGTHEX,Int Byte Ptr gt,0)
  1811. EndMethod
  1812. Method SetStyle(r,g,b,flags,pos,length,units)
  1813. Local iifont:ITextFont
  1814. Local iirange:ITextRange
  1815. Local res, tmpOutput
  1816. If units=TEXTAREA_LINES
  1817. Local n=pos
  1818. pos=CharAt(pos)
  1819. If length>=0 length=CharAt(n+length)-pos
  1820. EndIf
  1821. If length<0 length=charcount()-pos
  1822. busy:+1
  1823. res=idoc.Range(pos,pos+length,iirange)
  1824. res=iirange.GetFont(iifont)
  1825. res=iifont.SetForeColor(((b Shl 16)|(g Shl 8)|r))
  1826. If (flags&TEXTFORMAT_BOLD) Then iifont.SetBold(TOMTRUE) Else iifont.SetBold(TOMFALSE)
  1827. If (flags&TEXTFORMAT_ITALIC) Then iifont.SetItalic(TOMTRUE) Else iifont.SetItalic(TOMFALSE)
  1828. If (flags&TEXTFORMAT_UNDERLINE) Then iifont.SetUnderline(TOMSINGLE) Else iifont.SetUnderline(TOMFALSE)
  1829. If (flags&TEXTFORMAT_STRIKETHROUGH) Then iifont.SetStrikeThrough(TOMTRUE) Else iifont.SetStrikeThrough(TOMNONE)
  1830. iifont.Release_
  1831. iirange.Release_
  1832. busy:-1
  1833. EndMethod
  1834. Method InsertText(Text$,pos,count)
  1835. Local iirange:ITextRange
  1836. Local bstr:Short Ptr, tmpWString:Short Ptr = Text.toWString()
  1837. Local res, bool
  1838. busy:+1
  1839. res=idoc.Range(pos,pos+count,iirange)
  1840. bstr=SysAllocStringLen(tmpWString,Text.length);MemFree tmpWString
  1841. LockText()
  1842. res=iirange.SetText(bstr)
  1843. UnlockText()
  1844. SysFreeString bstr
  1845. iirange.Release_
  1846. busy:-1
  1847. EndMethod
  1848. Method ReplaceText(pos,length,Text$,units)
  1849. If units=TEXTAREA_LINES
  1850. Local n=pos
  1851. pos=CharAt(pos)
  1852. If length>=0 length=CharAt(n+length)-pos
  1853. EndIf
  1854. If length<0 Then length=charcount()-pos
  1855. InsertText Text,pos,length
  1856. EndMethod
  1857. Method AreaText$(pos,length,units)
  1858. Local iirange:ITextRange
  1859. Local bstr:Short Ptr
  1860. If units=TEXTAREA_LINES
  1861. Local n=pos
  1862. pos=CharAt(pos)
  1863. If length>=0 length=CharAt(n+length)-pos
  1864. EndIf
  1865. If length<0 length=charcount()-pos
  1866. idoc.Range(pos,pos+length,iirange)
  1867. iirange.GetText(Varptr bstr)
  1868. Local Text$=String.FromWString(bstr)
  1869. SysFreeString bstr
  1870. iirange.Release_
  1871. Text=Text.Replace(Chr(13),Chr(10))
  1872. Return Text
  1873. EndMethod
  1874. Method SetSelection(pos,length,units)
  1875. If units=TEXTAREA_LINES
  1876. Local n=pos
  1877. pos=CharAt(pos)
  1878. If length>0
  1879. length=CharAt(n+length)
  1880. length=length-pos
  1881. EndIf
  1882. EndIf
  1883. If length<0 length=charcount()-pos
  1884. Local cr:CHARRANGE = New CHARRANGE
  1885. cr.cpMin=pos
  1886. cr.cpMax=pos+length
  1887. Desensitize()
  1888. SendMessageW _hwnd,EM_EXSETSEL,0,Int Byte Ptr(cr)
  1889. Sensitize()
  1890. EndMethod
  1891. Method SetMargins(leftmargin)
  1892. SendMessageW _hwnd,EM_SETMARGINS,EC_LEFTMARGIN,leftmargin
  1893. EndMethod
  1894. ' 72 points per inch
  1895. Method SetTabs(tabs)
  1896. Local hdc=GetDC( 0 )
  1897. idoc.SetDefaultTabStop tabs * 72.0 / GetDeviceCaps( hdc,LOGPIXELSX )
  1898. ReleaseDC 0,hdc
  1899. EndMethod
  1900. Method SetTextColor(r,g,b)
  1901. cf.cbSize=SizeOf(CHARFORMATW)
  1902. cf.dwMask=CFM_COLOR|CFM_BOLD|CFM_ITALIC
  1903. cf.crTextColor=(b Shl 16)|(g Shl 8)|r
  1904. SendMessageW _hwnd,EM_SETCHARFORMAT,SCF_DEFAULT,Int Byte Ptr cf
  1905. SendMessageW _hwnd,EM_SETCHARFORMAT,SCF_ALL,Int Byte Ptr cf
  1906. EndMethod
  1907. Method SetColor(r,g,b)
  1908. SendMessageW _hwnd,EM_SETBKGNDCOLOR,0,((b Shl 16)|(g Shl 8)|r)
  1909. EndMethod
  1910. Method RemoveColor()
  1911. SendMessageW _hwnd,EM_SETBKGNDCOLOR,1,0
  1912. EndMethod
  1913. Method GetCursorPos(units)
  1914. Local cr:CHARRANGE = New CHARRANGE
  1915. SendMessageW _hwnd,EM_EXGETSEL,0,Int Byte Ptr(cr)
  1916. Local pos=cr.cpMin
  1917. If units=TEXTAREA_LINES pos=LineAt(pos)
  1918. Return pos
  1919. EndMethod
  1920. Method GetSelectionLength(units)
  1921. Local cr:CHARRANGE = New CHARRANGE
  1922. SendMessageW _hwnd,EM_EXGETSEL,0,Int Byte Ptr(cr)
  1923. If units=TEXTAREA_LINES
  1924. Return LineAt(cr.cpMax-1)-LineAt(cr.cpMin)+1
  1925. Else
  1926. Return cr.cpMax-cr.cpMin
  1927. EndIf
  1928. EndMethod
  1929. Method CharAt(Line)
  1930. If Line<0 Return
  1931. If Line>AreaLen(TEXTAREA_LINES) Return charcount()
  1932. Return SendMessageW(_hwnd,EM_LINEINDEX,Line,0)
  1933. EndMethod
  1934. Method LineAt(pos)
  1935. If pos<0 Return
  1936. If pos>charcount() Return AreaLen(TEXTAREA_LINES)
  1937. Return SendMessageW(_hwnd,EM_EXLINEFROMCHAR,0,pos)
  1938. EndMethod
  1939. Method AreaLen(units)
  1940. If units=TEXTAREA_LINES Return LineAt(charcount())
  1941. Return charcount()
  1942. EndMethod
  1943. Method CharX( char )
  1944. Local tmpPoint[2]
  1945. SendMessageW(_hwnd, EM_POSFROMCHAR, Int Byte Ptr tmpPoint, char )
  1946. Return tmpPoint[0]
  1947. EndMethod
  1948. Method CharY( char )
  1949. Local tmpPoint[2]
  1950. SendMessageW(_hwnd, EM_POSFROMCHAR, Int Byte Ptr tmpPoint, char )
  1951. Return tmpPoint[1]
  1952. EndMethod
  1953. Method SetText(Text$)
  1954. InsertText Text,0,charcount()
  1955. EndMethod
  1956. Method AddText(Text$)
  1957. InsertText Text,charcount(),0
  1958. Local cr:CHARRANGE = New CHARRANGE
  1959. Local p = charcount()
  1960. cr.cpMin=p
  1961. cr.cpMax=p
  1962. SendMessageW _hwnd,EM_EXSETSEL,0,Int Byte Ptr(cr)
  1963. EndMethod
  1964. Method GetText$()
  1965. Return AreaText(0,charcount(),TEXTAREA_CHARS)
  1966. EndMethod
  1967. Global _oldCursor = 0
  1968. Field _oldSelPos%, _oldSelLen% = 0
  1969. Method LockText()
  1970. If Not idoc.Freeze(_locked)
  1971. _oldSelPos = GetCursorPos(TEXTAREA_CHARS)
  1972. _oldSelLen = GetSelectionLength(TEXTAREA_CHARS)
  1973. If Not _oldCursor Then _oldCursor = GetCursor()
  1974. EndIf
  1975. EndMethod
  1976. Method UnlockText()
  1977. If idoc.Unfreeze(_locked) = S_OK Then
  1978. SetSelection( _oldSelPos, _oldSelLen, TEXTAREA_CHARS )
  1979. If _oldCursor And (_oldCursor <> GetCursor()) Then
  1980. SetCursor(_oldCursor)
  1981. EndIf
  1982. _oldCursor = 0
  1983. EndIf
  1984. EndMethod
  1985. Method OnCommand(msg,wp)
  1986. If busy Then Return
  1987. Select wp Shr 16
  1988. Case EN_CHANGE
  1989. If Not _locked Then PostGuiEvent EVENT_GADGETACTION
  1990. End Select
  1991. EndMethod
  1992. Method OnNotify(wp,lp)
  1993. Local nmhdr:Int Ptr
  1994. Local event:TEvent
  1995. Super.OnNotify(wp,lp) 'Tooltip
  1996. nmhdr=Int Ptr(lp)
  1997. Select nmhdr[2]
  1998. ' Case EN_PROTECTED
  1999. ' DebugStop
  2000. Case EN_SELCHANGE
  2001. If Not (busy Or _locked)
  2002. PostGuiEvent EVENT_GADGETSELECT
  2003. EndIf
  2004. Case EN_MSGFILTER
  2005. Select nmhdr[3]
  2006. Case WM_RBUTTONDOWN
  2007. If GetSelectionLength(TEXTAREA_CHARS)=0 nmhdr[3]=WM_LBUTTONDOWN
  2008. Case WM_RBUTTONUP
  2009. Local mx=nmhdr[5] & $ffff
  2010. Local my=nmhdr[5] Shr 16
  2011. PostGuiEvent EVENT_GADGETMENU,0,0,mx,my
  2012. Case WM_KEYDOWN
  2013. Local k=nmhdr[4]
  2014. 'Filtering out special shortcut combinations
  2015. If (keymods()&MODIFIER_CONTROL) Then
  2016. Select k
  2017. Case 76,69,82 'ctrl+l, ctrl+e, ctrl+r
  2018. Return 1 'Alignment shortcuts
  2019. Case 188,190 'ctrl+<, ctrl+>
  2020. 'Font size shortcuts
  2021. If (keymods()&MODIFIER_SHIFT) Then Return 1
  2022. EndSelect
  2023. EndIf
  2024. 'Read-only
  2025. If readonly
  2026. If k>=33 And k<=40 Return 0 'selection keys
  2027. If (keymods()&MODIFIER_CONTROL) Then
  2028. Select k
  2029. Case 65, 67;Return 0 'ctrl-a, ctrl+c
  2030. EndSelect
  2031. EndIf
  2032. Return 1
  2033. EndIf
  2034. 'Event Filter
  2035. If eventfilter<>Null
  2036. event=CreateEvent(EVENT_KEYDOWN,Self,k,keymods())
  2037. Return Not eventfilter(event,context)
  2038. EndIf
  2039. Case WM_CHAR
  2040. If readonly Return 1
  2041. If eventfilter<>Null
  2042. event=CreateEvent(EVENT_KEYCHAR,Self,nmhdr[4],keymods())
  2043. Return Not eventfilter(event,context)
  2044. EndIf
  2045. End Select
  2046. End Select
  2047. EndMethod
  2048. Method WndProc(hwnd,msg,wp,lp)
  2049. Select msg
  2050. Case WM_MOUSEWHEEL
  2051. If (wp&MK_CONTROL) Then SendMessageW _hwnd, EM_SETZOOM, 0, 0
  2052. Case WM_KILLFOCUS
  2053. PostGuiEvent EVENT_GADGETLOSTFOCUS
  2054. End Select
  2055. Return Super.WndProc(hwnd,msg,wp,lp)
  2056. EndMethod
  2057. Method Class()
  2058. Return GADGET_TEXTAREA
  2059. EndMethod
  2060. EndType
  2061. Type TWindowsListBox Extends TWindowsGadget
  2062. Field _icons:TWindowsIconStrip
  2063. Field _selected = -1
  2064. Method Create:TWindowsGadget(group:TGadget,style,Text$="")
  2065. Local xstyle,wstyle,hotkey
  2066. Local hwnd,parent
  2067. Self.style = style
  2068. xstyle=WS_EX_CLIENTEDGE
  2069. wstyle=WS_CHILD|WS_TABSTOP|LVS_REPORT|LVS_NOCOLUMNHEADER|LVS_SHOWSELALWAYS|LVS_SHAREIMAGELISTS
  2070. wstyle:|WS_CLIPSIBLINGS
  2071. If (style&LISTBOX_MULTISELECT<>LISTBOX_MULTISELECT) Then wstyle:|LVS_SINGLESEL
  2072. parent=group.query(QUERY_HWND_CLIENT)
  2073. hwnd=CreateWindowExW(xstyle,"SysListView32","",wstyle,0,0,20,20,parent,hotkey,GetModuleHandleW(Null),Null)
  2074. Local column:LVCOLUMNW
  2075. column=New LVCOLUMNW
  2076. SendMessageW hwnd,LVM_INSERTCOLUMNW,0,Int Byte Ptr(column)
  2077. SendMessageW hwnd,LVM_SETEXTENDEDLISTVIEWSTYLE,LVS_EX_FULLROWSELECT|LVS_EX_INFOTIP,LVS_EX_FULLROWSELECT|LVS_EX_INFOTIP
  2078. If TWindowsGUIDriver.CheckCommonControlVersion() Then SendMessageW hwnd,LVM_SETEXTENDEDLISTVIEWSTYLE,LVS_EX_DOUBLEBUFFER,LVS_EX_DOUBLEBUFFER
  2079. Register GADGET_LISTBOX,hwnd,0,False 'Set to True for normal Tooltips
  2080. If TWindowsGUIDriver._explorerstyle Then UseExplorerTheme()
  2081. Return Self
  2082. EndMethod
  2083. Method SetColor(r,g,b)
  2084. SendMessageW _hwnd,LVM_SETBKCOLOR ,0,(b Shl 16)|(g Shl 8)|r
  2085. SendMessageW _hwnd,LVM_SETTEXTBKCOLOR ,0,(b Shl 16)|(g Shl 8)|r
  2086. EndMethod
  2087. Method RemoveColor()
  2088. SendMessageW _hwnd,LVM_SETBKCOLOR ,1,0
  2089. SendMessageW _hwnd,LVM_SETTEXTBKCOLOR ,1,0
  2090. EndMethod
  2091. Method SetTextColor(r,g,b)
  2092. SendMessageW _hwnd,LVM_SETTEXTCOLOR,0,(b Shl 16)|(g Shl 8)|r
  2093. EndMethod
  2094. 'Hack: When image lists are removed from listviews, the items don't
  2095. 'reposition themselves automatically. Hack involves first setting a tiny
  2096. 'blank image-list to update item size, before attempting to remove it.
  2097. Method SetIconStrip(iconstrip:TIconStrip)
  2098. Local imagelist
  2099. If Not iconstrip Then
  2100. _icons = TWindowsIconStrip.CreateBlank()
  2101. Else
  2102. _icons = TWindowsIconStrip(iconstrip)
  2103. EndIf
  2104. If _icons Then imagelist = _icons._imagelist
  2105. SendMessageW _hwnd,LVM_SETIMAGELIST,LVSIL_SMALL,imagelist
  2106. If Not iconstrip Then
  2107. SendMessageW _hwnd,LVM_SETIMAGELIST,LVSIL_SMALL,0
  2108. _icons = Null
  2109. EndIf
  2110. EndMethod
  2111. Method ClearListItems()
  2112. _selected=-1
  2113. DeSensitize()
  2114. SendMessageW _hwnd,LVM_DELETEALLITEMS,0,0
  2115. If Not IsSingleSelect() Then SelectionChanged()
  2116. Sensitize()
  2117. EndMethod
  2118. Method InsertListItem(index,Text$,tip$,icon,tag:Object)
  2119. Local it:LVITEMW
  2120. it=New LVITEMW
  2121. it.mask=LVIF_TEXT|LVIF_DI_SETITEM
  2122. it.iItem=index
  2123. it.pszText=Text.toWString()
  2124. 'If icon>=0 Then
  2125. it.mask:|LVIF_IMAGE
  2126. it.iImage=icon
  2127. 'EndIf
  2128. Desensitize()
  2129. SendMessageW _hwnd,LVM_INSERTITEMW,0,Int Byte Ptr(it)
  2130. SendMessageW _hwnd,LVM_SETCOLUMNWIDTH,0,-2
  2131. If Not IsSingleSelect() Then SelectionChanged()
  2132. Sensitize()
  2133. MemFree it.pszText
  2134. EndMethod
  2135. Method SetListItem(index,Text$,tip$,icon,tag:Object)
  2136. Local tmpReselect
  2137. If ListItemState(index) & STATE_SELECTED Then tmpReselect = True
  2138. RemoveListItem index
  2139. InsertListItem index,Text,tip,icon,tag
  2140. If tmpReselect Then SetItemState(index,STATE_SELECTED)
  2141. EndMethod
  2142. Method RemoveListItem(index)
  2143. Desensitize()
  2144. If ListItemState(index) & STATE_SELECTED Then _selected = -1
  2145. SendMessageW _hwnd,LVM_DELETEITEM,index,0
  2146. SendMessageW _hwnd,LVM_SETCOLUMNWIDTH,0,-2
  2147. If Not IsSingleSelect() Then SelectionChanged()
  2148. Sensitize()
  2149. EndMethod
  2150. Method SetListItemState(index,state)
  2151. Local it:LVITEMW = New LVITEMW
  2152. it.mask=LVIF_STATE
  2153. it.iItem=index
  2154. If state&STATE_SELECTED
  2155. it.state=LVIS_SELECTED
  2156. If IsSingleSelect() Then _selected=index
  2157. ElseIf _selected=index
  2158. _selected=-1
  2159. EndIf
  2160. it.stateMask=LVIS_SELECTED
  2161. Desensitize()
  2162. SendMessageW _hwnd,LVM_SETITEMSTATE,index,Int Byte Ptr(it)
  2163. If it.state Then SendMessageW _hwnd,LVM_ENSUREVISIBLE,index,False
  2164. If Not IsSingleSelect() Then SelectionChanged()
  2165. Sensitize()
  2166. EndMethod
  2167. Method ListItemState(index)
  2168. Local state = SendMessageW(_hwnd,LVM_GETITEMSTATE,index,LVIS_SELECTED)
  2169. If state&LVIS_SELECTED Return STATE_SELECTED
  2170. EndMethod
  2171. Method SetTooltip( pTooltip$ )
  2172. 'ToolTips should be set on an item-by-item basis instead.
  2173. EndMethod
  2174. Method WndProc(hwnd,msg,wp,lp)
  2175. Select msg
  2176. Case WM_MAXGUILISTREFRESH
  2177. Local index
  2178. If IsSingleSelect() Then
  2179. index=SendMessageW(_hwnd,LVM_GETNEXTITEM,-1,LVNI_SELECTED)
  2180. Else
  2181. index = SelectionChanged()
  2182. EndIf
  2183. If index <> _selected Then
  2184. If IsSingleSelect() Then _selected = index
  2185. Local item:TGadgetItem = New TGadgetItem
  2186. If index>=0 And index<items.length item=items[index]
  2187. PostGuiEvent EVENT_GADGETSELECT,index,0,0,0,item.extra
  2188. EndIf
  2189. 'If we are using XP Common Controls or higher, then the listbox will be double-buffered
  2190. 'and so we don't need to clear the background (performance tweak).
  2191. Case WM_ERASEBKGND
  2192. If TWindowsGUIDriver.CheckCommonControlVersion() Then Return 1
  2193. EndSelect
  2194. Return Super.WndProc(hwnd,msg,wp,lp)
  2195. EndMethod
  2196. Method OnNotify(wp,lp)
  2197. Local nmhdr:Int Ptr = Int Ptr(lp)
  2198. Local index, code = nmhdr[2]
  2199. Select code
  2200. Case LVN_GETINFOTIPW
  2201. Local tmpItemIndex = nmhdr[6]
  2202. Local tmpMaxCharCount = nmhdr[5]-1
  2203. Local tmpTipOutput:Short Ptr = Short Ptr(nmhdr[4])
  2204. If tmpItemIndex < items.length Then
  2205. Local tmpTipString$ = items[tmpItemIndex].tip
  2206. If (items[tmpItemIndex].flags&GADGETITEM_LOCALIZED) Then tmpTipString = LocalizeString(tmpTipString)
  2207. tmpTipString = tmpTipString[..Min(tmpTipString.length,tmpMaxCharCount)]
  2208. Local tmpBufferMem:Short Ptr = tmpTipString.ToWString()
  2209. MemCopy tmpTipOutput, tmpBufferMem, (tmpTipString.length+1) * 2
  2210. MemFree tmpBufferMem
  2211. EndIf
  2212. Case LVN_ITEMCHANGED
  2213. 'We need to postpone processing until after *all* item states have been updated by the OS.
  2214. If Not(nmhdr[7]&LVIF_STATE) Then Return
  2215. PostMessageW( _hwnd, WM_MAXGUILISTREFRESH, 0, 0 )
  2216. Case NM_DBLCLK
  2217. index=nmhdr[3]
  2218. Local item:TGadgetItem
  2219. If index>=0 And index<items.length
  2220. item=items[index]
  2221. PostGuiEvent EVENT_GADGETACTION,index,0,0,0,item.extra
  2222. EndIf
  2223. Case NM_CLICK
  2224. index=nmhdr[3]
  2225. If index=-1 And _selected<>-1
  2226. _selected=-1
  2227. PostGuiEvent EVENT_GADGETSELECT,-1
  2228. EndIf
  2229. Case NM_RCLICK
  2230. index=nmhdr[3]
  2231. Local item:TGadgetItem
  2232. If index>=0 And index<items.length
  2233. item=items[index]
  2234. PostGuiEvent EVENT_GADGETMENU,index,0,0,0,item.extra
  2235. EndIf
  2236. 'Return true to tell the OS not to send individual LVN_DELETEITEM notifications for each and every item when clearing list.
  2237. Case LVN_DELETEALLITEMS
  2238. Return True
  2239. End Select
  2240. EndMethod
  2241. Method IsSingleSelect()
  2242. Return (style&LISTBOX_MULTISELECT<>LISTBOX_MULTISELECT)
  2243. EndMethod
  2244. Method Class()
  2245. Return GADGET_LISTBOX
  2246. EndMethod
  2247. Method HasResized()
  2248. SendMessageW _hwnd,LVM_SETCOLUMNWIDTH,0,-2
  2249. EndMethod
  2250. Method UseExplorerTheme()
  2251. If TWindowsGUIDriver.CheckCommonControlVersion() And SetWindowThemeW Then SetWindowThemeW( _hwnd, _wstrExplorer, Null )
  2252. EndMethod
  2253. EndType
  2254. Type TWindowsComboBox Extends TWindowsGadget
  2255. Field _icons:TWindowsIconStrip
  2256. Field _editHwnd, _comboHwnd
  2257. Field _selected = -1
  2258. Method Create:TWindowsGadget(group:TGadget,style,Text$="")
  2259. Local xstyle,wstyle,hotkey,hwnd
  2260. Local parent,editstyle,combostyle
  2261. Self.style = style
  2262. wstyle=WS_CHILD|WS_TABSTOP|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|CBS_AUTOHSCROLL
  2263. If (style & COMBOBOX_EDITABLE) Then wstyle:|CBS_DROPDOWN Else wstyle:|CBS_DROPDOWNLIST
  2264. parent=group.query(QUERY_HWND_CLIENT)
  2265. hwnd=CreateWindowExW(xstyle,"ComboBoxEx32","",wstyle,0,0,0,180,parent,hotkey,GetModuleHandleW(Null),Null)
  2266. If (style & COMBOBOX_EDITABLE) Then
  2267. _editHwnd=SendMessageW(hwnd,CBEM_GETEDITCONTROL,0,0)
  2268. If _editHwnd Then
  2269. editstyle=GetWindowLongW(_editHwnd,GWL_STYLE)
  2270. SetWindowLongW _editHwnd,GWL_STYLE,editstyle|WS_TABSTOP
  2271. EndIf
  2272. EndIf
  2273. _comboHwnd=SendMessageW(hwnd,CBEM_GETCOMBOCONTROL,0,0)
  2274. comboStyle=GetWindowLongW(_comboHwnd,GWL_STYLE)
  2275. SetWindowLongW _comboHwnd,GWL_STYLE,comboStyle|WS_TABSTOP
  2276. Register GADGET_COMBOBOX,hwnd
  2277. TWindowsGUIDriver.RegisterHwnd(_combohwnd,Self)
  2278. If _edithwnd Then TWindowsGUIDriver.RegisterHwnd(_edithwnd,Self)
  2279. SetColor(255,255,255)
  2280. Return Self
  2281. EndMethod
  2282. Method SetText(Text$)
  2283. If Not _editHwnd Then
  2284. Local tmpWString:Short Ptr = Text.ToWString()
  2285. Local tmpResult = SendMessageW(_comboHwnd, CB_SETCUEBANNER, 0, Int(tmpWString))
  2286. MemFree tmpWString;Return tmpResult
  2287. Else
  2288. Return Super.SetText(Text)
  2289. EndIf
  2290. EndMethod
  2291. Method GetText$()
  2292. If Not _editHwnd Then
  2293. If _selected > -1 Then Return items[_selected].Text Else Return ""
  2294. Else
  2295. Return Super.GetText()
  2296. EndIf
  2297. EndMethod
  2298. Method Activate(cmd)
  2299. If _editHwnd Then
  2300. Select cmd
  2301. Case ACTIVATE_CUT
  2302. SendMessageW _editHwnd,WM_CUT,0,0
  2303. Case ACTIVATE_COPY
  2304. SendMessageW _editHwnd,WM_COPY,0,0
  2305. SetFocus _hwnd
  2306. Case ACTIVATE_PASTE
  2307. SendMessageW _editHwnd,WM_PASTE,0,0
  2308. Case ACTIVATE_FOCUS
  2309. SendMessageW _editHwnd,EM_SETSEL,0,-1
  2310. End Select
  2311. EndIf
  2312. Return Super.Activate(cmd)
  2313. EndMethod
  2314. Method SetIconStrip(iconstrip:TIconStrip)
  2315. Local imagelist
  2316. _icons=TWindowsIconStrip(iconstrip)
  2317. If _icons Then imagelist = _icons._imagelist
  2318. SendMessageW _hwnd,CBEM_SETIMAGELIST,LVSIL_SMALL,imagelist
  2319. EndMethod
  2320. Method ClearListItems()
  2321. _selected=-1
  2322. Desensitize()
  2323. SendMessageW _hwnd,CB_RESETCONTENT,0,0
  2324. Sensitize()
  2325. EndMethod
  2326. Method InsertListItem(index,Text$,tip$,icon,tag:Object)
  2327. Local it:COMBOBOXEXITEMW = New COMBOBOXEXITEMW
  2328. it.mask=CBEIF_TEXT
  2329. it.iItem=index
  2330. it.pszText=Text.toWString()
  2331. If icon>=0
  2332. it.mask:|CBEIF_IMAGE|CBEIF_SELECTEDIMAGE
  2333. it.iImage=icon
  2334. it.iSelectedImage=icon
  2335. EndIf
  2336. Desensitize()
  2337. SendMessageW(_hwnd,CBEM_INSERTITEMW,0,Int Byte Ptr(it))
  2338. Sensitize()
  2339. MemFree it.pszText
  2340. EndMethod
  2341. Method SetListItem(index,Text$,tip$,icon,tag:Object)
  2342. Local it:COMBOBOXEXITEMW = New COMBOBOXEXITEMW
  2343. it.mask=CBEIF_TEXT
  2344. it.iItem=index
  2345. it.pszText=Text.toWString()
  2346. If _icons And icon>-1
  2347. it.mask:|CBEIF_IMAGE|CBEIF_SELECTEDIMAGE
  2348. it.iImage=icon
  2349. it.iSelectedImage=icon
  2350. EndIf
  2351. Desensitize()
  2352. SendMessageW(_hwnd,CBEM_SETITEMW,0,Int Byte Ptr(it))
  2353. Sensitize()
  2354. MemFree it.pszText
  2355. EndMethod
  2356. Method RemoveListItem(index)
  2357. Desensitize()
  2358. SendMessageW _hwnd,CBEM_DELETEITEM,index,0
  2359. Sensitize()
  2360. EndMethod
  2361. Method SetListItemState(index,state)
  2362. If state&STATE_SELECTED
  2363. _selected=index
  2364. Else
  2365. If _selected=index _selected=-1
  2366. index=-1
  2367. EndIf
  2368. Desensitize()
  2369. SendMessageW _hwnd,CB_SETCURSEL,index,0
  2370. Sensitize()
  2371. EndMethod
  2372. Method ListItemState(index)
  2373. Local Current,state
  2374. Current=SendMessageW(_hwnd,CB_GETCURSEL,0,0)
  2375. If Current=CB_ERR Current=-1
  2376. If Current=index state=STATE_SELECTED
  2377. Return state
  2378. EndMethod
  2379. Method OnCommand(msg,wp)
  2380. Local index
  2381. Select wp Shr 16
  2382. Case CBN_SELCHANGE
  2383. index=SendMessageW(_hwnd,CB_GETCURSEL,0,0)
  2384. If index=CB_ERR
  2385. index=-1
  2386. Else
  2387. If _selected<>index 'user generated event
  2388. _selected=index
  2389. Local extra:Object
  2390. If index>=0 And index<items.length extra=items[index].extra
  2391. PostGuiEvent EVENT_GADGETACTION,index,0,0,0,extra
  2392. EndIf
  2393. EndIf
  2394. Case CBN_EDITCHANGE
  2395. _selected=-1
  2396. PostGuiEvent EVENT_GADGETACTION,-1
  2397. End Select
  2398. EndMethod
  2399. Method Class()
  2400. Return GADGET_COMBOBOX
  2401. EndMethod
  2402. EndType
  2403. Type TWindowsToolbar Extends TWindowsGadget
  2404. Field _icons:TWindowsIconStrip
  2405. Method Create:TWindowsGadget(group:TGadget,style,Text$="")
  2406. Local xstyle,wstyle,hotkey
  2407. Local hwnd,parent
  2408. Self.style = style
  2409. xstyle=TBSTYLE_EX_DOUBLEBUFFER|TBSTYLE_EX_HIDECLIPPEDBUTTONS
  2410. wstyle=TBSTYLE_FLAT|WS_CHILD|WS_CLIPSIBLINGS|TBSTYLE_TRANSPARENT
  2411. Self.parent = group
  2412. parent=Self.parent.query(QUERY_HWND)
  2413. hwnd=CreateWindowExW(xstyle,"ToolbarWindow32","",wstyle,0,0,0,0,parent,hotkey,GetModuleHandleW(Null),Null)
  2414. DragAcceptFiles(hwnd,False) 'For some reason, toolbars may accept files by default!
  2415. Register GADGET_TOOLBAR,hwnd,0,True
  2416. SendMessageW _hwnd,TB_SETTOOLTIPS,_tooltips,0
  2417. Rethink()
  2418. Return Self
  2419. EndMethod
  2420. Method SetIconStrip(iconstrip:TIconStrip)
  2421. _icons=TWindowsIconStrip(iconstrip)
  2422. SendMessageW _hwnd,TB_SETIMAGELIST,0,_icons._imagelist
  2423. SendMessageW _hwnd,TB_AUTOSIZE,0,0
  2424. Rethink
  2425. EndMethod
  2426. Method SetShow(truefalse)
  2427. Super.SetShow(truefalse)
  2428. UpdateWindowClient()
  2429. EndMethod
  2430. Method Free()
  2431. SetShow(False)
  2432. Super.Free()
  2433. EndMethod
  2434. Method Rethink()
  2435. Local tmpRect[4]
  2436. GetWindowRect _hwnd,tmpRect
  2437. SetRect(0,0,parent.ClientWidth(),(tmpRect[3]-tmpRect[1]))
  2438. QueueResize _hwnd,xpos,ypos,width,height
  2439. UpdateWindowClient()
  2440. EndMethod
  2441. Method UpdateWindowClient()
  2442. Local tmpHeight:Int = height
  2443. If (State()&STATE_HIDDEN) Then tmpHeight = 0
  2444. If TWindowsGadget(parent)._clientY <> tmpHeight Then
  2445. TWindowsGadget(parent)._clientY = tmpHeight
  2446. parent.Rethink()
  2447. TWindowsGadget(parent).RethinkClient()
  2448. parent.LayoutKids()
  2449. EndIf
  2450. EndMethod
  2451. Method DoLayout()
  2452. Rethink()
  2453. EndMethod
  2454. Method SetTooltip( pTooltip$ )
  2455. 'ToolTips should be set on an item-by-item basis instead.
  2456. EndMethod
  2457. Method ClearListItems()
  2458. While SendMessageW(_hwnd,TB_BUTTONCOUNT,0,0)
  2459. RemoveListItem(0)
  2460. Wend
  2461. EndMethod
  2462. Method InsertListItem(index,Text$,tip$,icon,tag:Object)
  2463. Local but:TBBUTTON
  2464. but=New TBBUTTON
  2465. but.fsState=TBSTATE_ENABLED
  2466. If icon = -2 Or (icon>-1 And _icons.IsBlankIcon(icon))
  2467. but.idCommand=0
  2468. but.fsStyle=TBSTYLE_SEP
  2469. Else
  2470. but.iBitmap=icon
  2471. but.idCommand=index+1
  2472. but.fsStyle=TBSTYLE_BUTTON
  2473. EndIf
  2474. Desensitize()
  2475. SendMessageW _hwnd,TB_INSERTBUTTON,index,Int Byte Ptr(but)
  2476. Sensitize()
  2477. If tip
  2478. Local ti:TOOLINFOW=New TOOLINFOW
  2479. ti.cbSize=SizeOf(ti)
  2480. ti.uFlags=TTF_SUBCLASS
  2481. ti.hwnd=_hwnd
  2482. ti.lpszText=tip.towstring()
  2483. ti.uId=index+1
  2484. SendMessageW _hwnd,TB_GETITEMRECT,index,Int(Varptr ti.rect_left)
  2485. SendMessageW _tooltips,TTM_ADDTOOLW,0,Int Byte Ptr(ti)
  2486. MemFree ti.lpszText
  2487. EndIf
  2488. EndMethod
  2489. Method SetListItem(index,Text$,tip$,icon,tag:Object)
  2490. Local tmpState:Int = ListItemState(index)
  2491. RemoveListItem index
  2492. InsertListItem index,Text,tip,icon,tag
  2493. SetListItemState(index,tmpState)
  2494. EndMethod
  2495. Method RemoveListItem(index)
  2496. Local ti:TOOLINFOW=New TOOLINFOW
  2497. ti.cbSize=SizeOf(ti)
  2498. ti.hwnd=_hwnd
  2499. ti.uId=index+1
  2500. Desensitize()
  2501. SendMessageW _tooltips,TTM_DELTOOLW,0,Int(Varptr ti)
  2502. SendMessageW _hwnd,TB_DELETEBUTTON,index,0
  2503. Sensitize()
  2504. EndMethod
  2505. Method SetListItemState(index,state)
  2506. Local enable,pressed
  2507. If state&STATE_DISABLED=0 enable=$1
  2508. If state&STATE_SELECTED pressed=$1
  2509. SendMessageW _hwnd,TB_ENABLEBUTTON,index+1,enable
  2510. SendMessageW _hwnd,TB_CHECKBUTTON,index+1,pressed
  2511. EndMethod
  2512. Method ListItemState(index)
  2513. Local state,flags
  2514. state=SendMessageW(_hwnd,TB_GETSTATE,index+1,0)
  2515. If state=-1 Return 0
  2516. If Not (state&TBSTATE_ENABLED) flags:|STATE_DISABLED
  2517. If state&TBSTATE_CHECKED flags:|STATE_SELECTED
  2518. Return flags
  2519. EndMethod
  2520. Method OnCommand(msg,wp)
  2521. Local index=wp-1
  2522. Local extra:Object
  2523. If index>=0 And index<items.length extra=items[index].extra
  2524. PostGuiEvent EVENT_GADGETACTION,index,0,0,0,extra
  2525. EndMethod
  2526. Method Class()
  2527. Return GADGET_TOOLBAR
  2528. EndMethod
  2529. EndType
  2530. Type TWindowsTabber Extends TWindowsGadget
  2531. Field _icons:TWindowsIconStrip
  2532. Field _tabcount
  2533. Field _blank:Short Ptr
  2534. Field _selected = -1
  2535. Field _tipbuffer:Short Ptr
  2536. Method Create:TWindowsGadget(group:TGadget,style,Text$="")
  2537. Local xstyle,wstyle,hotkey
  2538. Local hwnd,parent,client
  2539. Self.style = style
  2540. xstyle=WS_EX_CONTROLPARENT
  2541. wstyle=WS_CHILD|TCS_HOTTRACK|WS_TABSTOP|TCS_FOCUSNEVER|WS_CLIPCHILDREN|WS_CLIPSIBLINGS
  2542. parent=group.query(QUERY_HWND_CLIENT)
  2543. hwnd=CreateWindowExW(xstyle,"SysTabControl32","",wstyle,0,0,0,0,parent,hotkey,GetModuleHandleW(Null),Null)
  2544. client=CreateWindowExW(xstyle,TWindowsGUIDriver.ClassName(),"",WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN,0,0,0,0,hwnd,0,GetModuleHandleW(Null),Null )
  2545. SendMessageW hwnd,TCM_INSERTITEMW,0,Int(_wstrSpace)
  2546. Register GADGET_TABBER,hwnd,client,True
  2547. SendMessageW _hwnd,TCM_SETTOOLTIPS,_tooltips,0
  2548. Return Self
  2549. EndMethod
  2550. Method SetIconStrip(iconstrip:TIconStrip)
  2551. Local imagelist
  2552. _icons=TWindowsIconStrip(iconstrip)
  2553. If _icons Then imagelist = _icons._imagelist
  2554. SendMessageW _hwnd,TCM_SETIMAGELIST,0,imagelist
  2555. RethinkClient()
  2556. EndMethod
  2557. Method ClientWidth()
  2558. Local Rect[] = [0,0,width,height]
  2559. SendMessageW _hwnd,TCM_ADJUSTRECT,False,Int Byte Ptr(Rect)
  2560. If Rect[2]>Rect[0] Then Return Rect[2]-Rect[0]
  2561. EndMethod
  2562. Method ClientHeight()
  2563. Local Rect[] = [0,0,width,height]
  2564. SendMessageW _hwnd,TCM_ADJUSTRECT,False,Int Byte Ptr(Rect)
  2565. If Rect[3]>Rect[1] Then Return Rect[3]-Rect[1]
  2566. EndMethod
  2567. Method ClearListItems()
  2568. _tabcount=0
  2569. _selected=-1
  2570. Desensitize()
  2571. SendMessageW _hwnd,TCM_DELETEALLITEMS, 0, 0
  2572. Sensitize()
  2573. RethinkClient()
  2574. EndMethod
  2575. Method InsertListItem(index,Text$,tip$,icon,tag:Object)
  2576. If _tabcount=0 SendMessageW _hwnd,TCM_DELETEALLITEMS,0,0
  2577. Local t:TCITEMW=New TCITEMW
  2578. t.mask=TCIF_TEXT|TCIF_IMAGE
  2579. t.pszText=Text.toWString()
  2580. t.iImage=icon
  2581. Desensitize()
  2582. SendMessageW _hwnd,TCM_INSERTITEMW,index,Int Byte Ptr(t)
  2583. Sensitize()
  2584. MemFree t.pszText
  2585. _tabcount:+1
  2586. RethinkClient()
  2587. EndMethod
  2588. Method SetListItem(index,Text$,tip$,icon,tag:Object)
  2589. Local t:TCITEMW=New TCITEMW
  2590. t.mask=TCIF_TEXT|TCIF_IMAGE
  2591. t.pszText=Text.toWString()
  2592. t.iImage=icon
  2593. Desensitize()
  2594. SendMessageW _hwnd,TCM_SETITEMW,index,Int Byte Ptr(t)
  2595. Sensitize()
  2596. MemFree t.pszText
  2597. RethinkClient()
  2598. EndMethod
  2599. Method RemoveListItem(index)
  2600. Desensitize()
  2601. SendMessageW _hwnd,TCM_DELETEITEM,index,0
  2602. _tabcount:-1
  2603. _selected=SendMessageW(_hwnd,TCM_GETCURSEL,0,0)
  2604. If _tabcount=0 SendMessageW _hwnd,TCM_INSERTITEMW,0,Int(_blank)
  2605. Sensitize()
  2606. RethinkClient()
  2607. EndMethod
  2608. Method SetListItemState(index,state)
  2609. Desensitize()
  2610. If state&STATE_SELECTED
  2611. _selected=index
  2612. SendMessageW _hwnd,TCM_SETCURSEL,index,0
  2613. ElseIf _selected=index
  2614. _selected=-1
  2615. EndIf
  2616. Sensitize()
  2617. EndMethod
  2618. Method ListItemState(index)
  2619. Local state,Current
  2620. Current=-1
  2621. If _tabcount Current=SendMessageW(_hwnd,TCM_GETCURSEL,0,0)
  2622. If Current=index state:|STATE_SELECTED
  2623. Return state
  2624. EndMethod
  2625. Method OnNotify(wp,lp)
  2626. Local nmhdr:Int Ptr 'hwnd,id,code
  2627. Local index
  2628. nmhdr=Int Ptr(lp)
  2629. Select nmhdr[2]
  2630. Case TTN_GETDISPINFOW
  2631. Local TCHITTESTINFO[3], Rect[4]
  2632. GetCursorPos_( TCHITTESTINFO );GetWindowRect( _hwnd, Rect )
  2633. TCHITTESTINFO = [TCHITTESTINFO[0]-Rect[0],TCHITTESTINFO[1]-Rect[1],0]
  2634. Local tmpItem = SendMessageW( _hwnd, TCM_HITTEST, 0, Int Byte Ptr TCHITTESTINFO )
  2635. If (tmpItem > -1) And (tmpItem < items.length) Then
  2636. Local tmpTooltip$ = items[tmpItem].tip
  2637. If (items[tmpItem].flags&GADGETITEM_LOCALIZED) Then tmpTooltip = LocalizeString(tmpTooltip)
  2638. SetTipBuffer( tmpTooltip )
  2639. If tmpTooltip Then nmhdr[3] = Int(_tipbuffer)
  2640. EndIf
  2641. Case TCN_SELCHANGE
  2642. If _tabcount
  2643. index=SendMessageW(_hwnd,TCM_GETCURSEL,0,0)
  2644. If index<>_selected
  2645. Local extra:Object
  2646. If index>=0 And index<items.length
  2647. extra=items[index].extra
  2648. Else
  2649. index=-1
  2650. EndIf
  2651. _selected=index
  2652. PostGuiEvent EVENT_GADGETACTION,index,0,0,0,extra
  2653. EndIf
  2654. EndIf
  2655. Case NM_RCLICK
  2656. Local TCHITTESTINFO[3], Rect[4], extra:Object
  2657. GetCursorPos_( TCHITTESTINFO );GetWindowRect( _hwnd, Rect )
  2658. TCHITTESTINFO = [TCHITTESTINFO[0]-Rect[0],TCHITTESTINFO[1]-Rect[1],0]
  2659. Local index = SendMessageW( _hwnd, TCM_HITTEST, 0, Int Byte Ptr TCHITTESTINFO )
  2660. If (index < 0) Or (index >= items.length) Then index = -1 Else extra = items[index].extra
  2661. PostGuiEvent EVENT_GADGETMENU,index,0,TCHITTESTINFO[0],TCHITTESTINFO[1],extra
  2662. EndSelect
  2663. EndMethod
  2664. Method WndProc(hwnd,msg,wp,lp)
  2665. Select msg
  2666. Case WM_ERASEBKGND
  2667. Select hwnd
  2668. Case _hwndclient
  2669. If DrawThemeParentBackground Then
  2670. DrawParentBackground(wp,hwnd)
  2671. Return 1
  2672. EndIf
  2673. EndSelect
  2674. End Select
  2675. Return Super.WndProc(hwnd,msg,wp,lp)
  2676. EndMethod
  2677. Method RethinkClient(forceRedraw:Int = False)
  2678. Local Rect[] = [0,0,width,height]
  2679. SendMessageW _hwnd,TCM_ADJUSTRECT,False, Int Byte Ptr(Rect)
  2680. MoveWindow _hwndclient,Rect[RECT_LEFT],Rect[RECT_TOP],Rect[RECT_RIGHT]-Rect[RECT_LEFT],Rect[RECT_BOTTOM]-Rect[RECT_TOP],forceRedraw
  2681. EndMethod
  2682. Method SetTipBuffer( pTip$ )
  2683. If _tipbuffer Then MemFree _tipbuffer
  2684. If pTip Then _tipbuffer = pTip.ToWString()
  2685. EndMethod
  2686. Method SetTooltip( pTooltip$ )
  2687. 'ToolTips should be set on an item-by-item basis instead.
  2688. EndMethod
  2689. Method Class()
  2690. Return GADGET_TABBER
  2691. EndMethod
  2692. EndType
  2693. Type TWindowsTreeNode Extends TGadget
  2694. Field _parent:TWindowsTreeNode
  2695. Field _tree 'HWND
  2696. Field _item 'HTREEITEM
  2697. Field _expanded
  2698. Field _icon
  2699. Field _handle
  2700. Method Activate(cmd)
  2701. Local tmpTree:TWindowsTreeView = TWindowsTreeView(TWindowsGUIDriver.GadgetFromHwnd(_tree))
  2702. If tmpTree Then tmpTree.Desensitize()
  2703. Select cmd
  2704. Case ACTIVATE_SELECT
  2705. If _item <> TVI_ROOT Then
  2706. SendMessageW _tree,TVM_SELECTITEM,TVGN_CARET,_item
  2707. Else
  2708. SendMessageW _tree,TVM_SELECTITEM,TVGN_CARET,0
  2709. EndIf
  2710. Case ACTIVATE_EXPAND
  2711. SendMessageW _tree,TVM_EXPAND,TVE_EXPAND,_item
  2712. _expanded=True
  2713. Case ACTIVATE_COLLAPSE
  2714. SendMessageW _tree,TVM_EXPAND,TVE_COLLAPSE,_item
  2715. _expanded=False
  2716. Case ACTIVATE_REDRAW
  2717. RedrawNode()
  2718. End Select
  2719. If tmpTree Then tmpTree.Sensitize()
  2720. EndMethod
  2721. Method CreateRoot:TWindowsTreeNode(owner:TWindowsTreeView)
  2722. _tree=owner._hwnd
  2723. _item=TVI_ROOT
  2724. Return Self
  2725. EndMethod
  2726. Method CountKids()
  2727. Return kids.count()
  2728. EndMethod
  2729. Method Create:TWindowsTreeNode(group:TGadget,style,Text$="",index=-1,icon = -1)
  2730. _parent=TWindowsTreeNode(group)
  2731. If Not _parent Throw "Parent isn't a treeview node. Use TreeViewRoot() when creating a root node."
  2732. Self.style = style
  2733. _tree=_parent._tree
  2734. _icon = icon
  2735. Spawn(Text,index)
  2736. _SetParent group,index
  2737. If (LocalizationMode()&LOCALIZATION_OVERRIDE) Then
  2738. LocalizeGadget(Self, Text, "")
  2739. EndIf
  2740. Return Self
  2741. EndMethod
  2742. Method GetText$()
  2743. Local item[10]
  2744. Local buffer:Short[260]
  2745. item[0]=TVIF_TEXT
  2746. item[1]=_item
  2747. item[4]=Int Byte Ptr buffer
  2748. item[5]=256
  2749. SendMessageW _tree,TVM_GETITEMW,0,Int Byte Ptr(item)
  2750. Return String.FromWString(buffer)
  2751. EndMethod
  2752. Method SetText(Text$)
  2753. Local tv:TVITEMW=New TVITEMW
  2754. tv.mask=TVIF_HANDLE|TVIF_TEXT
  2755. tv.hItem = _item
  2756. If _icon > -1 Then
  2757. tv.mask:|TVIF_IMAGE|TVIF_SELECTEDIMAGE
  2758. tv.iImage=_icon
  2759. tv.iSelectedImage=tv.iImage
  2760. EndIf
  2761. tv.pszText=Text.ToWString()
  2762. SendMessageW(_tree,TVM_SETITEMW,0,Int Byte Ptr tv)
  2763. MemFree tv.pszText
  2764. EndMethod
  2765. Method DoLayout()
  2766. 'Don't do anything!
  2767. EndMethod
  2768. Method Free()
  2769. 'If we don't have a parent then the node must have previously been freed.
  2770. If Not _parent Then Return
  2771. 'Avoid firing events when freeing a treenode that is selected.
  2772. If SendMessageW(_tree,TVM_GETNEXTITEM,TVGN_CARET,0) Then DeSelect()
  2773. 'Free treenode
  2774. If _item Then SendMessageW(_tree,TVM_DELETEITEM,0,_item);_item=0
  2775. 'Redraw parent if we were its last child node
  2776. If Not SendMessageW(_tree, TVM_GETNEXTITEM, TVGN_CHILD, _parent._item) Then _parent.RedrawNode()
  2777. 'Cleanup variables that could be circular references
  2778. _parent = Null;_tree = 0;_SetParent Null
  2779. 'Release any handle we created using HandleFromObject() in Spawn()
  2780. If _handle Then Release _handle
  2781. EndMethod
  2782. Method DeSelect()
  2783. SendMessageW _tree,TVM_SELECTITEM,TVGN_CARET,0
  2784. EndMethod
  2785. Method InsertNode:TGadget(index,Text$,icon)
  2786. Return New TWindowsTreeNode.Create(Self,0,Text,index,icon)
  2787. EndMethod
  2788. Method ModifyNode(Text$,icon)
  2789. _icon = icon
  2790. SetText Text
  2791. EndMethod
  2792. Method tviatindex(index)
  2793. If kids.IsEmpty() Then Return TVI_FIRST
  2794. If index<0 Or index>=kids.count() Return TVI_LAST
  2795. Local child:TWindowsTreeNode
  2796. child=TWindowsTreeNode(kids.valueatindex(index))
  2797. Return child._item
  2798. EndMethod
  2799. Method Spawn(name$,index=-1)
  2800. Local it:TVINSERTSTRUCTW
  2801. Local hitem
  2802. it=New TVINSERTSTRUCTW
  2803. it.hParent=_parent._item
  2804. If index = 0 Then
  2805. it.hInsertAfter = TVI_FIRST
  2806. Else
  2807. it.hInsertAfter=_parent.tviatindex(index-1)
  2808. EndIf
  2809. it.item_mask=TVIF_TEXT|TVIF_PARAM
  2810. If _icon > -1 Then
  2811. it.item_mask:|TVIF_IMAGE|TVIF_SELECTEDIMAGE
  2812. it.item_iImage=_icon
  2813. it.item_iSelectedImage=it.item_iImage
  2814. EndIf
  2815. Local tmpParentHadKids = SendMessageW(_tree, TVM_GETNEXTITEM, TVGN_CHILD, _parent._item)
  2816. it.item_pszText=name.ToWString()
  2817. it.item_lparam=HandleFromObject(Self)
  2818. 'Make sure that we store handle so we can release it later.
  2819. If _handle Then Release _handle
  2820. _handle = it.item_lparam
  2821. _item=SendMessageW(_tree,TVM_INSERTITEMW,0,Int Byte Ptr it)
  2822. MemFree it.item_pszText
  2823. 'Fix for tree-view parent status update problem.
  2824. If Not tmpParentHadKids Then _parent.RedrawNode()
  2825. Return _item
  2826. EndMethod
  2827. Method RedrawNode()
  2828. If _item = TVI_ROOT Then
  2829. InvalidateRect _tree, Null, True
  2830. Else
  2831. Local Rect[] = [_item,0,0,0]
  2832. If SendMessageW(_tree, TVM_GETITEMRECT, False, Int Byte Ptr Rect) Then
  2833. InvalidateRect _tree, Rect, True
  2834. EndIf
  2835. EndIf
  2836. EndMethod
  2837. Method SetTooltip( pTooltip$ )
  2838. 'At the moment, nodes don't support tooltips.
  2839. EndMethod
  2840. Method Class()
  2841. Return GADGET_NODE
  2842. EndMethod
  2843. EndType
  2844. Type TWindowsTreeView Extends TWindowsGadget
  2845. Field _root:TWindowsTreeNode
  2846. Field _selected:TWindowsTreeNode
  2847. Field _icons:TWindowsIconStrip
  2848. Method Create:TWindowsGadget(group:TGadget,style,Text$="")
  2849. Local xstyle,wstyle,hotkey
  2850. Local hwnd,parent
  2851. Self.style = style
  2852. xstyle=WS_EX_CLIENTEDGE
  2853. wstyle=WS_CHILD|TVS_HASLINES|TVS_HASBUTTONS|TVS_LINESATROOT|TVS_SHOWSELALWAYS|TVS_NOTOOLTIPS|WS_CLIPSIBLINGS
  2854. If Not(style&TREEVIEW_DRAGNDROP) wstyle:|TVS_DISABLEDRAGDROP
  2855. parent=group.query(QUERY_HWND_CLIENT)
  2856. hwnd=CreateWindowExW(xstyle,"SysTreeView32","",wstyle,0,0,0,0,parent,hotkey,GetModuleHandleW(Null),Null)
  2857. If TWindowsGUIDriver.CheckCommonControlVersion() Then SendMessageW hwnd, TVM_SETEXTENDEDSTYLE, TVS_EX_DOUBLEBUFFER, TVS_EX_DOUBLEBUFFER
  2858. Register GADGET_TREEVIEW,hwnd
  2859. _root=New TWindowsTreeNode.CreateRoot(Self)
  2860. If TWindowsGUIDriver._explorerstyle Then UseExplorerTheme()
  2861. Return Self
  2862. EndMethod
  2863. Method SetIconStrip(iconstrip:TIconStrip)
  2864. _icons=TWindowsIconStrip(iconstrip)
  2865. SendMessageW _hwnd,TVM_SETIMAGELIST,TVSIL_NORMAL,_icons._imagelist
  2866. EndMethod
  2867. Method SetColor(r,g,b)
  2868. SendMessageW _hwnd,TVM_SETBKCOLOR,0,(b Shl 16)|(g Shl 8)|r
  2869. EndMethod
  2870. Method RemoveColor()
  2871. SendMessageW _hwnd,TVM_SETBKCOLOR,1,0
  2872. EndMethod
  2873. Method SetTextColor(r,g,b)
  2874. SendMessageW _hwnd,TVM_SETTEXTCOLOR,0,(b Shl 16)|(g Shl 8)|r
  2875. EndMethod
  2876. Method RootNode:TGadget()
  2877. Return _root
  2878. EndMethod
  2879. Method SelectedNode:TGadget()
  2880. Return _selected
  2881. EndMethod
  2882. Method CountKids()
  2883. Return _root.CountKids()
  2884. EndMethod
  2885. Method OnNotify(wp,lp)
  2886. Local nmhdr:Int Ptr
  2887. Local itemnew:Int Ptr
  2888. Local node:TWindowsTreeNode
  2889. Super.OnNotify(wp,lp) 'Tool-tips
  2890. nmhdr=Int Ptr(lp)
  2891. Select nmhdr[2] 'code
  2892. 'MSLU glitch requires handling of ANSI equivalent
  2893. Case TVN_SELCHANGEDW, TVN_SELCHANGEDA
  2894. itemnew=nmhdr+14 'Int Ptr(nmhdr[5]) 'itemNew
  2895. If itemnew[1]=TVI_ROOT 'hItem
  2896. _selected=_root
  2897. Else
  2898. _selected=TWindowsTreeNode(HandleToObject(itemnew[9])) 'lParaM
  2899. EndIf
  2900. PostGuiEvent EVENT_GADGETSELECT,0,0,0,0,_selected
  2901. Case TVN_ITEMEXPANDEDW, TVN_ITEMEXPANDEDA
  2902. itemnew=nmhdr+14 'Int Ptr(nmhdr[5]) 'itemNew.TVITEM
  2903. If itemnew[1]=TVI_ROOT 'hItem
  2904. node=_root
  2905. Else
  2906. node=TWindowsTreeNode(HandleToObject(itemnew[9] )) 'lParaM
  2907. EndIf
  2908. Select nmhdr[3] 'action itemnew[2]&TVIS_EXPANDED 'state
  2909. Case 1
  2910. PostGuiEvent EVENT_GADGETCLOSE,0,0,0,0,node
  2911. node._expanded=False
  2912. Case 2
  2913. PostGuiEvent EVENT_GADGETOPEN,0,0,0,0,node
  2914. node._expanded=True
  2915. End Select
  2916. Return True
  2917. Case TVN_BEGINDRAGW, TVN_BEGINRDRAGW, TVN_BEGINDRAGA, TVN_BEGINRDRAGA
  2918. If (style&TREEVIEW_DRAGNDROP) Then
  2919. Local data% = 1
  2920. If (nmhdr[2] = TVN_BEGINRDRAGW) Or (nmhdr[2] = TVN_BEGINRDRAGA) Then data = 2
  2921. itemnew=nmhdr+14 'Int Ptr(nmhdr[5]) 'itemNew
  2922. If itemnew[1]<>TVI_ROOT Then
  2923. TGadget.dragGadget[data-1]=TWindowsTreeNode(HandleToObject(itemnew[9]))
  2924. PostGuiEvent EVENT_GADGETDRAG, data, KeyMods(), itemnew[10], itemnew[11], TGadget.dragGadget[data-1]
  2925. Else
  2926. TGadget.dragGadget[data-1]=Null
  2927. EndIf
  2928. EndIf
  2929. Case NM_DBLCLK, NM_RETURN
  2930. PostGuiEvent EVENT_GADGETACTION,0,0,0,0,_selected
  2931. Case NM_RCLICK
  2932. Local Rect[4]
  2933. Local pt[2]
  2934. Local hittest[4]
  2935. Local item[10]
  2936. GetWindowRect _hwnd,Rect
  2937. GetCursorPos_ pt
  2938. hittest[0]=pt[0]-Rect[0]
  2939. hittest[1]=pt[1]-Rect[1]
  2940. If SendMessageW(_hwnd,TVM_HITTEST,0,Int Byte Ptr(hittest))
  2941. If hittest[3]=TVI_ROOT
  2942. node=_root
  2943. Else
  2944. item[0]=TVIF_PARAM
  2945. item[1]=hittest[3]
  2946. SendMessageW _hwnd,TVM_GETITEMW,0,Int Byte Ptr(item)
  2947. node=TWindowsTreeNode(HandleToObject(item[9]))
  2948. EndIf
  2949. PostGuiEvent EVENT_GADGETMENU,0,hittest[0],hittest[1],0,node
  2950. EndIf
  2951. Return True
  2952. EndSelect
  2953. EndMethod
  2954. Method WndProc(hwnd,msg,wp,lp)
  2955. Select msg
  2956. 'If we are using Vista's common controls, then the treeview will be double-buffered and so
  2957. 'we don't need to clear the background when redrawing (performance tweak).
  2958. Case WM_ERASEBKGND
  2959. If TWindowsGUIDriver.CheckCommonControlVersion() >= 2 Then Return 1
  2960. EndSelect
  2961. Return Super.WndProc(hwnd,msg,wp,lp)
  2962. EndMethod
  2963. Method UseExplorerTheme()
  2964. If TWindowsGUIDriver.CheckCommonControlVersion() And SetWindowThemeW Then
  2965. SetWindowThemeW( _hwnd, _wstrExplorer, Null )
  2966. SendMessageW _hwnd, TVM_SETEXTENDEDSTYLE, TVS_EX_FADEINOUTEXPANDOS, TVS_EX_FADEINOUTEXPANDOS
  2967. EndIf
  2968. EndMethod
  2969. Method Class()
  2970. Return GADGET_TREEVIEW
  2971. EndMethod
  2972. EndType
  2973. Type TWindowsLabel Extends TWindowsGadget
  2974. Method Create:TWindowsGadget(group:TGadget,style,Text$="")
  2975. Local xstyle,wstyle,hotkey
  2976. Local hwnd,parent
  2977. Self.style = style
  2978. wstyle=WS_CHILD|SS_NOPREFIX|WS_CLIPSIBLINGS|SS_NOTIFY
  2979. Select style&24
  2980. Case LABEL_LEFT wstyle:|SS_LEFT
  2981. Case LABEL_RIGHT wstyle:|SS_RIGHT
  2982. Case LABEL_CENTER wstyle:|SS_CENTER
  2983. End Select
  2984. Select style&7
  2985. Case LABEL_FRAME wstyle:|WS_BORDER
  2986. Case LABEL_SUNKENFRAME wstyle:|SS_SUNKEN
  2987. Case LABEL_SEPARATOR wstyle:|SS_SUNKEN|SS_GRAYRECT
  2988. End Select
  2989. parent=group.query(QUERY_HWND_CLIENT)
  2990. hwnd=CreateWindowExW(xstyle,"STATIC","",wstyle,0,0,0,0,parent,hotkey,GetModuleHandleW(Null),Null)
  2991. Register GADGET_LABEL,hwnd
  2992. Return Self
  2993. EndMethod
  2994. Method SetArea(x,y,w,h)
  2995. If ((style & 7) = LABEL_SEPARATOR) Then
  2996. If (w > h) Then h = 2 Else w = 2
  2997. EndIf
  2998. Return Super.SetArea(x,y,w,h)
  2999. EndMethod
  3000. Method SetText(Text$)
  3001. If ((style & 7) <> LABEL_SEPARATOR) Then Return Super.SetText(Text)
  3002. EndMethod
  3003. Method WndProc(hwnd,msg,wp,lp)
  3004. Select msg
  3005. Case WM_ERASEBKGND
  3006. Return 1
  3007. EndSelect
  3008. Return Super.WndProc(hwnd,msg,wp,lp)
  3009. EndMethod
  3010. Method Class()
  3011. Return GADGET_LABEL
  3012. EndMethod
  3013. EndType
  3014. Type TWindowsSlider Extends TWindowsGadget
  3015. Field _slidertype,_ishorizontal,_visible = 5,_total = 10,_value
  3016. Method Create:TWindowsGadget(group:TGadget,style,Text$="")
  3017. Local xstyle,wstyle,class$
  3018. Local hwnd,parent,hotkey
  3019. _slidertype=style&$fffc
  3020. _ishorizontal=style&SLIDER_HORIZONTAL
  3021. Self.style = style
  3022. wstyle=WS_CHILD|WS_CLIPSIBLINGS|WS_CLIPCHILDREN
  3023. parent=group.query(QUERY_HWND_CLIENT)
  3024. Select _slidertype
  3025. Case SLIDER_SCROLLBAR
  3026. If _ishorizontal wstyle:|SBS_HORZ;Else wstyle:|SBS_VERT
  3027. class$="SCROLLBAR"
  3028. Case SLIDER_TRACKBAR
  3029. wstyle:|TBS_AUTOTICKS|WS_TABSTOP
  3030. xstyle:|WS_EX_COMPOSITED 'Reduces flicker when resizing (doesn't like scrollbars/up-down controls)
  3031. If _ishorizontal wstyle:|TBS_HORZ Else wstyle:|TBS_VERT
  3032. class$=TRACKBAR_CLASS
  3033. Case SLIDER_STEPPER
  3034. If _ishorizontal wstyle:|UDS_HORZ
  3035. class$="msctls_updown32"
  3036. Default
  3037. Return Null
  3038. End Select
  3039. hwnd=CreateWindowExW(xstyle,class,"",wstyle,0,0,0,0,parent,hotkey,GetModuleHandleW(Null),Null)
  3040. Register GADGET_SLIDER,hwnd
  3041. RefreshLook()
  3042. Return Self
  3043. EndMethod
  3044. Method SetRange(visible,total)
  3045. _visible = visible
  3046. _total = total
  3047. Local tmpEnabled:Int = Not( State() & STATE_DISABLED )
  3048. Desensitize()
  3049. Select _slidertype
  3050. Case SLIDER_SCROLLBAR
  3051. Local info:SCROLLINFO=New SCROLLINFO
  3052. info.cbSize=SizeOf(SCROLLINFO)
  3053. info.fMask=SIF_PAGE|SIF_RANGE
  3054. info.nMax=total-1
  3055. info.nPage=visible
  3056. SendMessageW _hwnd,SBM_SETSCROLLINFO,True,Int Byte Ptr info
  3057. Case SLIDER_TRACKBAR
  3058. SendMessageW _hwnd,TBM_SETRANGEMIN,False,visible
  3059. SendMessageW _hwnd,TBM_SETRANGEMAX,True,total
  3060. ' Aesthetic tweak that should stop black tick bands forming when
  3061. ' large ranges are used on small trackbars.
  3062. Local tmpFirstTick% = SendMessageW( _hwnd, TBM_GETTICPOS, 0, 0 )
  3063. Local tmpNumTicks% = SendMessageW( _hwnd, TBM_GETNUMTICS, 0, 0)
  3064. Local tmpLastTick% = SendMessageW( _hwnd, TBM_GETTICPOS, tmpNumTicks-3, 0 )
  3065. If Not( tmpLastTick < 0 Or tmpFirstTick < 0 Or (total-visible-2) < 1) Then
  3066. If (tmpLastTick-tmpFirstTick)/(total-visible-2) < 4 Then
  3067. SendMessageW( _hwnd, TBM_CLEARTICS, True, 0 )
  3068. EndIf
  3069. EndIf
  3070. Case SLIDER_STEPPER
  3071. SendMessageW _hwnd,UDM_SETRANGE32,visible,total
  3072. End Select
  3073. _value = GetProp()
  3074. SetEnabled(tmpEnabled)
  3075. Sensitize()
  3076. EndMethod
  3077. Method SetProp(value)
  3078. Desensitize()
  3079. Select _slidertype
  3080. Case SLIDER_SCROLLBAR
  3081. Local info:SCROLLINFO=New SCROLLINFO
  3082. info.cbSize=SizeOf(SCROLLINFO)
  3083. info.fMask=SIF_POS
  3084. info.nPos=value
  3085. SendMessageW _hwnd,SBM_SETSCROLLINFO,True,Int Byte Ptr info
  3086. Case SLIDER_TRACKBAR
  3087. If _ishorizontal Then
  3088. SendMessageW _hwnd,TBM_SETPOS,True,value
  3089. Else
  3090. 'Flip the value so that the scale starts from the bottom
  3091. SendMessageW _hwnd,TBM_SETPOS,True,_visible + _total - value
  3092. EndIf
  3093. Case SLIDER_STEPPER
  3094. SendMessageW _hwnd,UDM_SETPOS,True,value
  3095. End Select
  3096. _value = value
  3097. Sensitize()
  3098. EndMethod
  3099. Method GetProp()
  3100. Local value
  3101. Select _slidertype
  3102. Case SLIDER_SCROLLBAR
  3103. value=GetScrollPos(_hwnd,SB_CTL)
  3104. Case SLIDER_TRACKBAR
  3105. value=SendMessageW(_hwnd,TBM_GETPOS,0,0)
  3106. 'Flip the value so that the scale starts from the bottom
  3107. If Not _ishorizontal Then value = _visible + _total - value
  3108. Case SLIDER_STEPPER
  3109. value=SendMessageW(_hwnd,UDM_GETPOS32,0,Null)
  3110. End Select
  3111. Return value
  3112. EndMethod
  3113. Method OnCommand(msg,wp)
  3114. If _slidertype=SLIDER_SCROLLBAR
  3115. If msg=WM_COMMAND Return
  3116. Local info:SCROLLINFO=New SCROLLINFO
  3117. info.cbSize=SizeOf(SCROLLINFO)
  3118. Select wp&$ffff
  3119. Case SB_THUMBTRACK,SB_THUMBPOSITION
  3120. info.fMask=SIF_TRACKPOS
  3121. SendMessageW _hwnd,SBM_GETSCROLLINFO,0,Int Byte Ptr info
  3122. SetScrollPos _hwnd,SB_CTL,info.nTrackPos,True
  3123. Default
  3124. info.fMask=SIF_POS|SIF_PAGE|SIF_RANGE
  3125. SendMessageW _hwnd,SBM_GETSCROLLINFO,0,Int Byte Ptr info
  3126. Local pos=info.nPos
  3127. Local vis=info.nPage
  3128. Select wp&$ffff
  3129. Case SB_LINEUP pos:-1
  3130. Case SB_LINEDOWN pos:+1
  3131. Case SB_PAGEUP pos:-vis
  3132. Case SB_PAGEDOWN pos:+vis
  3133. Default Return 0
  3134. End Select
  3135. SetScrollPos _hwnd,SB_CTL,pos,True
  3136. End Select
  3137. EndIf
  3138. Local index=GetProp()
  3139. If (index <> _value) Then
  3140. PostGuiEvent EVENT_GADGETACTION,index
  3141. _value = index
  3142. EndIf
  3143. Return 1
  3144. EndMethod
  3145. Method WndProc(hwnd,msg,wp,lp)
  3146. Select msg
  3147. Case WM_ERASEBKGND
  3148. Return 1
  3149. EndSelect
  3150. Return Super.WndProc(hwnd,msg,wp,lp)
  3151. EndMethod
  3152. Method RefreshLook()
  3153. Super.RefreshLook()
  3154. SetRange(_visible,_total)
  3155. EndMethod
  3156. Method Class()
  3157. Return GADGET_SLIDER
  3158. EndMethod
  3159. EndType
  3160. Type TWindowsProgressBar Extends TWindowsGadget
  3161. Method Create:TWindowsGadget(group:TGadget,style,Text$="")
  3162. Local xstyle,wstyle,hotkey
  3163. Local hwnd,parent
  3164. Self.style = style
  3165. wstyle=WS_CHILD|PBS_SMOOTH|WS_CLIPSIBLINGS
  3166. parent=group.query(QUERY_HWND_CLIENT)
  3167. hwnd=CreateWindowExW(xstyle,"msctls_progress32","",wstyle,0,0,0,0,parent,hotkey,GetModuleHandleW(Null),Null)
  3168. Register GADGET_PROGBAR,hwnd
  3169. Return Self
  3170. EndMethod
  3171. Method SetValue(value#)
  3172. SendMessageW _hwnd,PBM_SETPOS,value*100,0
  3173. EndMethod
  3174. Method SetColor(r,g,b)
  3175. 'Only works in Classic mode, but it's better than nothing.
  3176. SendMessageW _hwnd,PBM_SETBKCOLOR ,0,(b Shl 16)|(g Shl 8)|r
  3177. EndMethod
  3178. Method RemoveColor()
  3179. 'Only works in Classic mode, but it's better than nothing.
  3180. SendMessageW _hwnd,PBM_SETBKCOLOR ,1,0
  3181. EndMethod
  3182. Method SetTextColor(r,g,b)
  3183. 'Only works in Classic mode, but it's better than nothing.
  3184. SendMessageW _hwnd,PBM_SETBARCOLOR ,0,(b Shl 16)|(g Shl 8)|r
  3185. EndMethod
  3186. Method Class()
  3187. Return GADGET_PROGBAR
  3188. EndMethod
  3189. EndType
  3190. Type TWindowsPanel Extends TWindowsGadget
  3191. Const PANELPANEL=0
  3192. Const PANELGROUP=1
  3193. Const PANELCANVAS=2
  3194. Field _type
  3195. Field _alpha#=1.0
  3196. Field _bitmapwidth,_bitmapheight,_bitmapflags
  3197. Field _canvas:TGraphics
  3198. Field _hasalpha
  3199. Method Create:TWindowsGadget(group:TGadget,style,Text$="")
  3200. Local xstyle,wstyle,hotkey
  3201. Local hwnd,client,parent
  3202. Self.style = style
  3203. parent=group.query(QUERY_HWND_CLIENT)
  3204. If (style&3=PANEL_GROUP) Then
  3205. _type=PANELGROUP
  3206. hwnd=CreateWindowExW(WS_EX_CONTROLPARENT,"BUTTON","",BS_GROUPBOX|WS_CHILD|WS_CLIPSIBLINGS|WS_CLIPCHILDREN,0,0,0,0,parent,0,GetModuleHandleW(Null),Null )
  3207. client=CreateWindowExW(WS_EX_CONTROLPARENT,TWindowsGUIDriver.ClassName(),"",WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,0,0,0,0,hwnd,0,GetModuleHandleW(Null),Null)
  3208. Else
  3209. _type=PANELPANEL
  3210. xstyle=WS_EX_CONTROLPARENT
  3211. wstyle=WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS
  3212. Select (style&3)
  3213. Case PANEL_SUNKEN xstyle:|WS_EX_CLIENTEDGE
  3214. Case PANEL_RAISED xstyle:|WS_EX_WINDOWEDGE ; wstyle:|WS_DLGFRAME
  3215. EndSelect
  3216. If (style&PANEL_CANVAS) Then _type=PANELCANVAS
  3217. hwnd=CreateWindowExW(xstyle,TWindowsGUIDriver.ClassName(),"",wstyle,0,0,0,0,parent,hotkey,GetModuleHandleW(Null),Null)
  3218. EndIf
  3219. Register GADGET_PANEL,hwnd,client
  3220. If (style & PANEL_ACTIVE) Then sensitivity = SENSITIZE_ALL
  3221. Return Self
  3222. EndMethod
  3223. Method SetAlpha( alpha# )
  3224. _alpha=alpha
  3225. RedrawGadget(Self)
  3226. EndMethod
  3227. Method Activate( cmd )
  3228. Select cmd
  3229. Case ACTIVATE_REDRAW
  3230. If (_type = PANELCANVAS) Then
  3231. InvalidateRect _hwnd, Null, False
  3232. Return True
  3233. EndIf
  3234. EndSelect
  3235. Return Super.Activate(cmd)
  3236. EndMethod
  3237. Method SetPixmap(pixmap:TPixmap,flags)
  3238. If _bitmap Then DeleteObject _bitmap;_bitmap = 0
  3239. If pixmap Then
  3240. If pixmap.format=PF_RGBA8888 Or pixmap.format=PF_BGRA8888
  3241. _bitmap=TWindowsGraphic.PreMultipliedBitmapFromPixmap32( pixmap )
  3242. EndIf
  3243. If _bitmap
  3244. _hasalpha=True
  3245. Else
  3246. _bitmap=TWindowsGraphic.BitmapFromPixmap( pixmap, False )
  3247. _hasalpha=False
  3248. EndIf
  3249. _bitmapflags=flags
  3250. _bitmapwidth=pixmap.width
  3251. _bitmapheight=pixmap.height
  3252. EndIf
  3253. RedrawGadget(Self)
  3254. EndMethod
  3255. Method AttachGraphics:TGraphics( flags )
  3256. _canvas=brl.Graphics.AttachGraphics( _hwnd,flags )
  3257. EndMethod
  3258. Method CanvasGraphics:TGraphics()
  3259. Return _canvas
  3260. EndMethod
  3261. Method Free()
  3262. If _canvas Then CloseGraphics(_canvas);_canvas = Null
  3263. Super.Free()
  3264. EndMethod
  3265. Method WndProc(hwnd,msg,wp,lp)
  3266. Select msg
  3267. Case WM_ERASEBKGND
  3268. If _type = PANELCANVAS Then Return 1
  3269. Local hdc=wp,hdcCanvas,hdcBitmap,srcw,srch,x,y,xoffset,yoffset
  3270. Local clientRect[4], updateRect[4], clipRect[4], windowRect[4]
  3271. GetClipBox( hdc, clipRect )
  3272. GetWindowRect( hwnd, windowRect)
  3273. GetClientRect( hwnd, clientRect )
  3274. If Not GetUpdateRect( hwnd, updateRect, False) Then updateRect = clipRect
  3275. If IsRectEmpty(updateRect) Then updateRect = [0,0,windowRect[2]-windowRect[0],windowRect[3]-windowRect[1]]
  3276. 'If we are drawing a bitmap or using alpha then let's do some double-buffering stuff
  3277. If (hwnd <> _hwndclient) And ((_bitmap And _bitmapwidth And _bitmapheight) Or _alpha<1.0) Then
  3278. hdc = CreateCompatibleDC(wp)
  3279. hdcCanvas = CreateCompatibleBitmap(wp,windowRect[2]-windowRect[0],windowRect[3]-windowRect[1])
  3280. SelectObject( hdc, hdcCanvas )
  3281. EndIf
  3282. 'Fill the drawing context with the background colour, or the background of the parent
  3283. If BgBrush() And (hwnd <> _hwndclient) Then FillRect(hdc,updateRect,BgBrush()) Else DrawParentBackground(hdc,hwnd)
  3284. 'If we aren't drawing to a bitmap or using alpha, then we can return now.
  3285. If Not ((hwnd <> _hwndclient) And ((_bitmap And _bitmapwidth And _bitmapheight) Or _alpha<1.0)) Then Return 1
  3286. If _bitmap And _bitmapwidth And _bitmapheight
  3287. hdcBitmap=CreateCompatibleDC(hdc)
  3288. SelectObject(hdcBitmap,_bitmap)
  3289. srcw=_bitmapwidth
  3290. srch=_bitmapheight
  3291. Select (_bitmapflags & (GADGETPIXMAP_ICON-1))
  3292. Case PANELPIXMAP_TILE
  3293. While y<windowRect[RECT_BOTTOM]-windowRect[RECT_TOP]
  3294. x=0
  3295. While x<windowRect[RECT_RIGHT]-windowRect[RECT_LEFT]
  3296. If _hasalpha
  3297. AlphaBlend_ hdc,x,y,srcw,srch,hdcBitmap,0,0,srcw,srch,$01ff0000
  3298. Else
  3299. BitBlt hdc,x,y,srcw,srch,hdcBitmap,0,0,ROP_SRCCOPY
  3300. EndIf
  3301. x:+srcw
  3302. Wend
  3303. y:+srch
  3304. Wend
  3305. Case PANELPIXMAP_CENTER
  3306. x=(windowRect[RECT_RIGHT]-windowRect[RECT_LEFT]-srcw)/2
  3307. y=(windowRect[RECT_BOTTOM]-windowRect[RECT_TOP]-srch)/2
  3308. If _hasalpha
  3309. AlphaBlend_ hdc,x,y,srcw,srch,hdcBitmap,0,0,srcw,srch,$01ff0000
  3310. Else
  3311. BitBlt hdc,x,y,srcw,srch,hdcBitmap,0,0,ROP_SRCCOPY
  3312. EndIf
  3313. Case PANELPIXMAP_FIT, PANELPIXMAP_FIT2
  3314. Local mx# = Float(windowRect[RECT_RIGHT]-windowRect[RECT_LEFT])/srcw
  3315. Local my# = Float(windowRect[RECT_BOTTOM]-windowRect[RECT_TOP])/srch
  3316. If mx>my Then
  3317. If (_bitmapflags&(GADGETPIXMAP_ICON-1)) = PANELPIXMAP_FIT Then mx=my Else my=mx
  3318. EndIf
  3319. Local w=mx*srcw
  3320. Local h=mx*srch
  3321. x=(windowRect[RECT_RIGHT]-windowRect[RECT_LEFT]-w)/2
  3322. y=(windowRect[RECT_BOTTOM]-windowRect[RECT_TOP]-h)/2
  3323. SetStretchBltMode hdc,COLORONCOLOR
  3324. If _hasalpha
  3325. AlphaBlend_ hdc,x,y,w,h,hdcBitmap,0,0,srcw,srch,$01ff0000
  3326. Else
  3327. StretchBlt hdc,x,y,w,h,hdcBitmap,0,0,srcw,srch,ROP_SRCCOPY
  3328. EndIf
  3329. Case PANELPIXMAP_STRETCH
  3330. SetStretchBltMode hdc,COLORONCOLOR
  3331. If _hasalpha
  3332. AlphaBlend_ hdc,0,0,windowRect[RECT_RIGHT]-windowRect[RECT_LEFT],windowRect[RECT_BOTTOM]-windowRect[RECT_TOP],hdcBitmap,0,0,srcw,srch,$01ff0000
  3333. Else
  3334. StretchBlt hdc,0,0,windowRect[RECT_RIGHT]-windowRect[RECT_LEFT],windowRect[RECT_BOTTOM]-windowRect[RECT_TOP],hdcBitmap,0,0,srcw,srch,ROP_SRCCOPY
  3335. EndIf
  3336. EndSelect
  3337. DeleteDC(hdcBitmap)
  3338. EndIf
  3339. If _alpha < 1.0 Then
  3340. DrawParentBackground( wp, hwnd )
  3341. Local blendfunction = ((Int(_alpha*255)&$FF) Shl 16)
  3342. AlphaBlend_(wp,updateRect[0],updateRect[1],updateRect[2]-updateRect[0],updateRect[3]-updateRect[1],hdc,updateRect[0],updateRect[1],updateRect[2]-updateRect[0],updateRect[3]-updateRect[1],blendfunction)
  3343. Else
  3344. BitBlt(wp,0,0,windowRect[2]-windowRect[0],WindowRect[3]-windowRect[1],hdc,0,0,ROP_SRCCOPY)
  3345. EndIf
  3346. Assert hdc <> wp, "hdc == wp! Please post a MaxGUI bug report."
  3347. DeleteObject( hdcCanvas )
  3348. DeleteDC( hdc )
  3349. Return 1
  3350. Case WM_PAINT
  3351. Select _type
  3352. Case PANELCANVAS
  3353. PostGuiEvent EVENT_GADGETPAINT
  3354. ValidateRect _hwnd, Null
  3355. Return 1
  3356. EndSelect
  3357. Case WM_LBUTTONDOWN
  3358. SetFocus Query(QUERY_HWND_CLIENT)
  3359. End Select
  3360. Return Super.WndProc(hwnd,msg,wp,lp)
  3361. EndMethod
  3362. Method FlushBrushes(pRecurse:Int = True)
  3363. Super.FlushBrushes()
  3364. If Not pRecurse Then Return
  3365. For Local tmpGadget:TWindowsGadget = EachIn kids
  3366. tmpGadget.FlushBrushes()
  3367. Next
  3368. EndMethod
  3369. Method ClientWidth()
  3370. If _hwndClient Then Return (Super.ClientWidth()-8) Else Return Super.ClientWidth()
  3371. EndMethod
  3372. Method ClientHeight()
  3373. If _hwndClient Then Return (Super.ClientHeight()-20) Else Return Super.ClientHeight()
  3374. EndMethod
  3375. Method RethinkClient(forceRedraw:Int = False)
  3376. If _hwndClient Then
  3377. MoveWindow( _hwndClient, 4+_clientX,16+_clientY,ClientWidth(),ClientHeight(),forceRedraw)
  3378. EndIf
  3379. EndMethod
  3380. Method Class()
  3381. If _type = PANELCANVAS Then Return GADGET_CANVAS Else Return GADGET_PANEL
  3382. EndMethod
  3383. EndType
  3384. Type TWindowsHTMLView Extends TWindowsGadget
  3385. Field mshtml
  3386. Field browser:IWebBrowser2
  3387. Field IID_IHTMLDocument2:GUID=New GUID
  3388. Method Create:TWindowsGadget(group:TGadget,style,Text$="")
  3389. Self.style = style
  3390. Local parent=group.query(QUERY_HWND_CLIENT)
  3391. mshtml=msHtmlCreate(Self,TWindowsGUIDriver.ClassName(),parent,style)
  3392. browser=msHTMLBrowser(mshtml)
  3393. Register GADGET_HTMLVIEW,msHtmlHwnd(mshtml)
  3394. Local res = IIDFromString(IHTMLDocument2_UUID,IID_IHTMLDocument2)
  3395. Return Self
  3396. EndMethod
  3397. Method Rethink()
  3398. msHtmlSetShape mshtml,xpos,ypos,width,height
  3399. EndMethod
  3400. Method SetText(Text$) 'sets document url
  3401. If Text Then msHtmlGo mshtml,Text
  3402. EndMethod
  3403. Method GetText$()
  3404. Local bstr:Short Ptr
  3405. browser.lfget_LocationURL(Varptr bstr)
  3406. Local result$ = String.FromWString(bstr)
  3407. SysFreeString(bstr)
  3408. Return result
  3409. EndMethod
  3410. Method GetTitleText$() 'returns document title
  3411. Local bstr:Short Ptr
  3412. Local res
  3413. Local disp:IDispatch
  3414. Local doc:IHTMLDOCUMENT2
  3415. res=browser.lfget_Document(Varptr disp)
  3416. If res RuntimeError "no document"
  3417. res=disp.QueryInterface(IID_IHTMLDocument2,Varptr doc)
  3418. If res RuntimeError "no document2 interface"
  3419. If doc
  3420. doc.get_Title(Varptr bstr)
  3421. Else
  3422. browser.lfget_LocationName(Varptr bstr)
  3423. EndIf
  3424. Local result$ = String.FromWString(bstr)
  3425. SysFreeString(bstr)
  3426. Return result
  3427. End Method
  3428. Rem
  3429. Method Run$(script$)
  3430. Local res
  3431. Local disp:IDispatch
  3432. Local doc:IHTMLDOCUMENT2
  3433. Local win:IHTMLWindow2
  3434. Local result:VARIANT
  3435. res=browser.lfget_Document(Varptr disp)
  3436. If res RuntimeError "no document"
  3437. res=disp.QueryInterface(IID_IHTMLDocument2,Varptr doc)
  3438. If res RuntimeError "no document2 interface"
  3439. res=doc.get_parentWindow(Varptr win)
  3440. If res RuntimeError "no parent window"
  3441. result=New VARIANT
  3442. result.vt=VT_EMPTY
  3443. Local bstr:Short Ptr
  3444. bstr=SysAllocStringLen(script.toWString(),script.length)
  3445. res=win.execScript(bstr,Null,result)
  3446. SysFreeString bstr
  3447. Return res
  3448. End Method
  3449. EndRem
  3450. Method Activate(cmd)
  3451. Return msHtmlActivate(mshtml,cmd)
  3452. EndMethod
  3453. Method State()
  3454. Return msHtmlStatus(mshtml)
  3455. EndMethod
  3456. Method Run$(script$)
  3457. msHtmlRun(mshtml,script)
  3458. EndMethod
  3459. Method WndProc(hwnd,msg,wp,lp)
  3460. Select msg
  3461. 'Reduces flicker on HTMLViews
  3462. Case WM_ERASEBKGND
  3463. Return 1
  3464. EndSelect
  3465. Return Super.WndProc(hwnd,msg,wp,lp)
  3466. EndMethod
  3467. Method Class()
  3468. Return GADGET_HTMLVIEW
  3469. EndMethod
  3470. EndType
  3471. Type TWindowsMenu Extends TGadget
  3472. Field _hmenu
  3473. Field _pmenu
  3474. Field _item
  3475. Field _state
  3476. Field _tag
  3477. Field _hotkeycode
  3478. Field _modifier
  3479. Field _shortcut$
  3480. Field _hotkey:THotKey
  3481. Field _key = SetNewKey()
  3482. Field _iconBitmap
  3483. Global iteminfo:MENUITEMINFOW
  3484. Global keymap:TMap=New TMap 'key,gadget
  3485. Global keycount=100
  3486. Method SetNewKey%()
  3487. keycount:+1
  3488. keymap.Insert( TIntWrapper.Create(keycount), Self )
  3489. Return keycount
  3490. EndMethod
  3491. Function GetMenuFromKey:TWindowsMenu(pKey%)
  3492. Return TWindowsMenu(keymap.ValueForKey(TIntWrapper.Create(pKey)))
  3493. EndFunction
  3494. Method SetText(pText$)
  3495. name = pText
  3496. EndMethod
  3497. Method GetText$()
  3498. Return name
  3499. EndMethod
  3500. Method Free()
  3501. Close
  3502. _setparent Null
  3503. keymap.Remove(TIntWrapper.Create(_key))
  3504. If _iconBitmap Then DeleteObject(_iconBitmap)
  3505. EndMethod
  3506. Method DoLayout()
  3507. 'Don't do anything!
  3508. EndMethod
  3509. Method State()
  3510. Return _state
  3511. EndMethod
  3512. Method SetEnabled(enable)
  3513. If enable
  3514. If _pmenu EnableMenuItem(_pmenu,_item,MF_BYPOSITION|MF_ENABLED)
  3515. _state:&~STATE_DISABLED
  3516. Else
  3517. If _pmenu EnableMenuItem(_pmenu,_item,MF_BYPOSITION|MF_GRAYED)
  3518. _state:|STATE_DISABLED
  3519. EndIf
  3520. EndMethod
  3521. Method SetSelected(bool)
  3522. If bool
  3523. If _pmenu CheckMenuItem(_pmenu,_item,MF_BYPOSITION|MF_CHECKED)
  3524. _state:|STATE_SELECTED
  3525. Else
  3526. If _pmenu CheckMenuItem(_pmenu,_item,MF_BYPOSITION|MF_UNCHECKED)
  3527. _state:&~STATE_SELECTED
  3528. EndIf
  3529. EndMethod
  3530. Method SetHotKey(keycode,modifier)
  3531. _hotkeycode=keycode
  3532. _modifier=modifier
  3533. Local pre$, suf$, m$
  3534. If LocalizationMode()&LOCALIZATION_ON Then
  3535. pre="{{"
  3536. suf="}}"
  3537. EndIf
  3538. If keycode>=KEY_0 And keycode<=KEY_9
  3539. m$=Chr(keycode)
  3540. ElseIf keycode>=KEY_A And keycode<=KEY_Z
  3541. m$=Chr(keycode)
  3542. ElseIf keycode>=KEY_F1 And keycode<=KEY_F12
  3543. m$="F"+(keycode+1-KEY_F1)
  3544. ElseIf keycode>=KEY_NUM0 And keycode<=KEY_NUM9
  3545. m$="Num "+(keycode+1-KEY_NUM0)
  3546. Else
  3547. Select keycode
  3548. Case KEY_BACKSPACE;m = pre+"Backspace"+suf
  3549. Case KEY_TAB;m = pre+"Tab"+suf
  3550. Case KEY_ESCAPE;m = pre+"Esc"+suf
  3551. Case KEY_SPACE;m = pre+"Space"+suf
  3552. Case KEY_ENTER;m = pre+"Enter"+suf
  3553. Case KEY_PAGEUP;m = pre+"PageUp"+suf
  3554. Case KEY_PAGEDOWN;m = pre+"PageDown"+suf
  3555. Case KEY_END;m = pre+"End"+suf
  3556. Case KEY_HOME;m = pre+"Home"+suf
  3557. Case KEY_LEFT;m = pre+"Left"+suf
  3558. Case KEY_RIGHT;m = pre+"Right"+suf
  3559. Case KEY_UP;m = pre+"Up"+suf
  3560. Case KEY_DOWN;m = pre+"Down"+suf
  3561. Case KEY_INSERT;m = pre+"Insert"+suf
  3562. Case KEY_DELETE;m = pre+"Delete"+suf
  3563. Case KEY_TILDE;m = "~~"
  3564. Case KEY_MINUS;m = "-"
  3565. Case KEY_EQUALS;m = "="
  3566. Case KEY_OPENBRACKET;m = "["
  3567. Case KEY_CLOSEBRACKET;m = "]"
  3568. Case KEY_BACKSLASH;m = "\"
  3569. Case KEY_SEMICOLON;m = ";"
  3570. Case KEY_QUOTES;m = "'"
  3571. Case KEY_COMMA;m = ","
  3572. Case KEY_PERIOD;m = "."
  3573. Case KEY_SLASH;m = "/"
  3574. Case KEY_NUMMULTIPLY;m = "Num *"
  3575. Case KEY_NUMADD;m = "Num +"
  3576. Case KEY_NUMSUBTRACT;m = "Num -"
  3577. Case KEY_NUMDECIMAL;m = "Num ."
  3578. Case KEY_NUMDIVIDE;m = "Num /"
  3579. EndSelect
  3580. EndIf
  3581. If m
  3582. If modifier&MODIFIER_SHIFT m$=pre+"Shift"+suf+"+"+m$
  3583. If modifier&MODIFIER_CONTROL m$=pre+"Ctrl"+suf+"+"+m$
  3584. If modifier&MODIFIER_ALT m$=pre+"Alt"+suf+"+"+m$
  3585. m="~t"+m
  3586. EndIf
  3587. _shortcut$=LocalizeString(m)
  3588. If Not iteminfo
  3589. iteminfo=New MENUITEMINFOW
  3590. iteminfo.cbSize=SizeOf(iteminfo)
  3591. EndIf
  3592. iteminfo.fMask=MIIM_TYPE
  3593. iteminfo.dwTypeData=(name+_shortcut).toWString()
  3594. SetMenuItemInfoW _pmenu,_item,True,iteminfo
  3595. MemFree iteminfo.dwTypeData
  3596. Local ev:TEvent=CreateEvent( EVENT_MENUACTION, Self,_tag )
  3597. If _hotKey RemoveHotKey(_hotKey);_hotKey = Null
  3598. If keycode Then _hotkey=SetHotKeyEvent(keycode,modifier,ev,FindGadgetWindowHwnd(Self))
  3599. EndMethod
  3600. Method Create:TWindowsMenu(group:TGadget,tag,Text$="")
  3601. If Not iteminfo Then
  3602. iteminfo=New MENUITEMINFOW
  3603. iteminfo.cbSize=SizeOf(iteminfo)
  3604. EndIf
  3605. name=Text
  3606. _tag=tag
  3607. Local window:TWindowsWindow = TWindowsWindow(group)
  3608. If window group=window.GetMenu()
  3609. _SetParent(group)
  3610. If (LocalizationMode()&LOCALIZATION_OVERRIDE) Then
  3611. LocalizeGadget(Self, name, "")
  3612. EndIf
  3613. Return Self
  3614. EndMethod
  3615. Method Open(popup=False)
  3616. Local dad:TWindowsMenu = TWindowsMenu(parent)
  3617. If dad
  3618. _pmenu=dad._hmenu
  3619. If Not _pmenu Throw "Parent doesn't have a handle - the desktop heap may have run out of memory!"
  3620. _item=GetMenuItemCount(_pmenu)
  3621. If name
  3622. Local tmpWString:Short Ptr = (LocalizeString(name)+_shortcut).ToWString()
  3623. AppendMenuW _pmenu,MF_STRING,_key,tmpWString
  3624. MemFree tmpWString
  3625. Else
  3626. AppendMenuW _pmenu,MF_SEPARATOR,_key,Null
  3627. EndIf
  3628. If kids.count()
  3629. _hmenu=CreateMenu_()
  3630. Local tmpMenuInfo:MENUINFO = New MENUINFO
  3631. tmpMenuInfo.fMask = MIM_APPLYTOSUBMENUS|MIM_STYLE
  3632. tmpMenuInfo.dwStyle = MNS_CHECKORBMP|MNS_MODELESS
  3633. SetMenuInfo(_hmenu, tmpMenuInfo)
  3634. iteminfo.fMask=MIIM_SUBMENU
  3635. iteminfo.hSubMenu=_hmenu
  3636. SetMenuItemInfoW _pmenu,_item,True,iteminfo
  3637. EndIf
  3638. If _state&STATE_DISABLED SetEnabled(False)
  3639. If _state&STATE_SELECTED SetSelected(True)
  3640. If _iconBitmap Then SetMenuItemBitmaps(_pMenu,_key,MF_BYCOMMAND,_iconBitmap,Null)
  3641. Else
  3642. If popup
  3643. _hmenu=CreatePopupMenu()
  3644. Else
  3645. If kids _hmenu=CreateMenu_()
  3646. EndIf
  3647. EndIf
  3648. For Local kid:TWindowsMenu = EachIn kids
  3649. kid.Open
  3650. Next
  3651. EndMethod
  3652. Method FreeKids()
  3653. For Local kid:TWindowsMenu = EachIn kids
  3654. kid.Close
  3655. Next
  3656. EndMethod
  3657. Method Close()
  3658. FreeKids()
  3659. If _hmenu
  3660. DestroyMenu _hmenu
  3661. _hmenu=0
  3662. EndIf
  3663. EndMethod
  3664. Method SetPixmap(pixmap:TPixmap,pFlags)
  3665. If Not (pFlags & GADGETPIXMAP_ICON) Then Return
  3666. If _iconBitmap Then DeleteObject(_iconBitmap);_iconBitmap = 0
  3667. If pixmap Then
  3668. pixmap = PixmapWindow(pixmap,0,0,Min(GetSystemMetrics(SM_CXMENUCHECK),PixmapWidth(pixmap)),Min(GetSystemMetrics(SM_CYMENUCHECK),PixmapHeight(pixmap)))
  3669. If TWindowsGUIDriver.CheckCommonControlVersion() >= 2 Then
  3670. _iconBitmap = TWindowsGraphic.PreMultipliedBitmapFromPixmap32( pixmap )
  3671. Else
  3672. Local tmpRGB = GetSysColor(COLOR_MENU)
  3673. _iconBitmap = TWindowsGraphic.BitmapWithBackgroundFromPixmap32( pixmap, tmpRGB&$FF, (tmpRGB Shr 8) & $FF, (tmpRGB Shr 16) & $FF )
  3674. EndIf
  3675. EndIf
  3676. EndMethod
  3677. Method SetTooltip( pTooltip$ )
  3678. 'Menus shouldn't have tool-tips.
  3679. EndMethod
  3680. Method Class()
  3681. Return GADGET_MENUITEM
  3682. EndMethod
  3683. EndType
  3684. Type TWindowsIconStrip Extends TIconStrip
  3685. Field _blanks[]
  3686. Field _imagelist
  3687. Function DetectNotBlank(pixmap:TPixmap,xx,n)
  3688. Local c = pixmap.ReadPixel(xx,0), y
  3689. For Local x=0 Until n
  3690. For y=0 Until n
  3691. If pixmap.ReadPixel(xx+x,y)<>c Return True
  3692. Next
  3693. Next
  3694. EndFunction
  3695. Method IsBlankIcon(n)
  3696. Return _blanks[n]
  3697. EndMethod
  3698. Function RemoveMask(pixmap:TPixmap)
  3699. If pixmap.format<>( PF_RGBA8888 ) And pixmap.format<>( PF_BGRA8888 ) Return
  3700. Local w = pixmap.width, h = pixmap.height, y, c
  3701. For Local x=0 Until w
  3702. For y=0 Until h
  3703. c=pixmap.ReadPixel(x,y)
  3704. If c>=0 pixmap.WritePixel x,y,-1
  3705. Next
  3706. Next
  3707. EndFunction
  3708. Function BuildImageList(pixmap:TPixmap)
  3709. Local bitmap,imagelist,sz,mask
  3710. sz=pixmap.height
  3711. If TWindowsGUIDriver.CheckCommonControlVersion() And (Pixmap.format=PF_RGBA8888 Or pixmap.format=PF_BGRA8888)
  3712. imagelist=ImageList_Create(sz,sz,ILC_COLOR32,0,1)
  3713. If imagelist
  3714. bitmap=TWindowsGraphic.BitmapFromPixmap(pixmap, True)
  3715. ImageList_Add(imagelist,bitmap,0)
  3716. EndIf
  3717. EndIf
  3718. If imagelist=0
  3719. bitmap=TWindowsGraphic.BitmapFromPixmap(pixmap, False)
  3720. mask=TWindowsGraphic.BitmapMaskFromPixmap(pixmap)
  3721. imagelist=ImageList_Create(sz,sz,ILC_COLOR24|ILC_MASK,0,1)
  3722. ImageList_Add(imagelist,bitmap,mask)
  3723. DeleteObject(mask)
  3724. EndIf
  3725. DeleteObject(bitmap)
  3726. Return imagelist
  3727. EndFunction
  3728. Function Create:TWindowsIconStrip(source:Object)
  3729. Local icons:TWindowsIconStrip
  3730. Local imagelist
  3731. Local n,i,sz
  3732. Local blanks[]
  3733. 'Get a 24-bit pixmap from source
  3734. Local pix:TPixmap = TPixmap(source)
  3735. If Not pix pix = LoadPixmap(source)
  3736. If Not pix Return
  3737. 'Detect blank icons in the set
  3738. sz=pix.height;If sz n=pix.width/sz
  3739. If n=0 Return
  3740. blanks=New Int[n]
  3741. For i=0 Until n
  3742. blanks[i]=Not DetectNotBlank(pix,i*sz,sz)
  3743. Next
  3744. 'Build a Win32 Image-List
  3745. imagelist=BuildImageList(pix)
  3746. icons = New TWindowsIconStrip
  3747. icons.pixmap = pix
  3748. icons.count=n
  3749. icons._blanks=blanks
  3750. icons._imagelist=imagelist
  3751. Return icons
  3752. EndFunction
  3753. Function CreateBlank:TWindowsIconStrip()
  3754. Return Create(CreatePixmap(1,1,PF_BGR888))
  3755. EndFunction
  3756. Method Delete()
  3757. If _imagelist Then
  3758. ImageList_Destroy(_imagelist)
  3759. _imagelist = 0
  3760. EndIf
  3761. EndMethod
  3762. EndType
  3763. Type TWindowsFont Extends TGuiFont
  3764. Method Load:TWindowsFont(_name$,_size:Double,_style)
  3765. If handle Then DeleteObject handle;handle = 0
  3766. Local cfweight = FW_NORMAL
  3767. Local cfsize = -LogicalUnitsFromSize( _size )
  3768. If _style & FONT_BOLD cfweight=FW_BOLD
  3769. handle=CreateFontW( cfsize, 0,0,0,cfweight,..
  3770. (_style & FONT_ITALIC) ,..
  3771. (_style & FONT_UNDERLINE),..
  3772. (_style & FONT_STRIKETHROUGH),..
  3773. DEFAULT_CHARSET,..
  3774. OUT_DEFAULT_PRECIS,..
  3775. CLIP_DEFAULT_PRECIS,..
  3776. ANTIALIASED_QUALITY,..
  3777. DEFAULT_PITCH|FF_DONTCARE,..
  3778. _name.toWString())
  3779. 'Now lets test to see whether the right font was found
  3780. name = NameFromHandle(handle)
  3781. 'If the font returned has a different name to that requested, let's try the symbol character set
  3782. If name.ToLower() <> _name.ToLower() Then
  3783. Local tmpSymbolHandle = CreateFontW( cfsize, 0,0,0,cfweight,..
  3784. (_style & FONT_ITALIC) ,..
  3785. (_style & FONT_UNDERLINE),..
  3786. (_style & FONT_STRIKETHROUGH),..
  3787. SYMBOL_CHARSET,..
  3788. OUT_DEFAULT_PRECIS,..
  3789. CLIP_DEFAULT_PRECIS,..
  3790. ANTIALIASED_QUALITY,..
  3791. DEFAULT_PITCH|FF_DONTCARE,..
  3792. _name.toWString())
  3793. Local strSymbolName:String = NameFromHandle(tmpSymbolHandle)
  3794. 'If we now have a match, delete the first font returned and use the new symbol one.
  3795. If strSymbolName.ToLower() = _name.ToLower() Then
  3796. DeleteObject handle
  3797. handle = tmpSymbolHandle
  3798. name = strSymbolName
  3799. Else
  3800. DeleteObject tmpSymbolHandle
  3801. EndIf
  3802. EndIf
  3803. size=_size
  3804. style=_style
  3805. Return Self
  3806. EndMethod
  3807. Method LoadFromLogFont:TWindowsFont( pLogFont:LOGFONTW, pStyle% = 0, pSize:Double = 0:Double )
  3808. If pLogFont.lfWeight>=FW_BOLD Then pStyle:| FONT_BOLD
  3809. If pLogFont.lfItalic Then pStyle:| FONT_ITALIC
  3810. If pLogFont.lfUnderline Then pStyle:| FONT_UNDERLINE
  3811. If pLogFont.lfStrikeOut Then pStyle:| FONT_STRIKETHROUGH
  3812. style = pStyle
  3813. If Not pSize Then pSize = SizeFromLogFont( pLogFont )
  3814. size = pSize
  3815. SetLogFontProperties( pLogFont, pStyle, pSize )
  3816. name = String.FromWString( Varptr pLogFont.lfFaceName00 )
  3817. If handle Then DeleteObject handle
  3818. handle = CreateFontIndirectW( pLogFont )
  3819. Return Self
  3820. EndMethod
  3821. Method LoadFromHandle:TWindowsFont(hfont)
  3822. Local tmpLogFont:LOGFONTW = New LOGFONTW
  3823. GetObjectW( hfont, SizeOf(LOGFONTW), tmpLogFont )
  3824. Return LoadFromLogFont( tmpLogFont )
  3825. EndMethod
  3826. Method CharWidth( charcode )
  3827. Local hdc=GetDC(0)
  3828. Local tfont=SelectObject( hdc,handle )
  3829. Local width=8,widths[3]
  3830. If GetCharABCWidthsW( hdc,charcode,charcode,widths )
  3831. width=widths[0]+widths[1]+widths[2]
  3832. Else If GetCharWidth32W( hdc,charcode,charcode,widths )
  3833. width=widths[0]
  3834. EndIf
  3835. SelectObject hdc,tfont
  3836. ReleaseDC 0,hdc
  3837. Return width
  3838. EndMethod
  3839. Method GetMaxCharWidth()
  3840. Local hdc=GetDC(0)
  3841. Local tfont=SelectObject(hdc,handle)
  3842. Local tm:TEXTMETRIC=New TEXTMETRIC
  3843. GetTextMetricsW hdc,tm
  3844. SelectObject(hdc,tfont)
  3845. ReleaseDC(0,hdc)
  3846. Return tm.tmAveCharWidth
  3847. EndMethod
  3848. Method Delete()
  3849. If handle Then DeleteObject handle
  3850. EndMethod
  3851. Function Request:TWindowsFont(font:TGuiFont)
  3852. Local lf:LOGFONTW = New LOGFONTW
  3853. Local cf:CHOOSEFONT = New CHOOSEFONT
  3854. cf.lStructSize=SizeOf(cf)
  3855. cf.hwndOwner=TWindowsGUIDriver.GetActiveHwnd()
  3856. cf.lpLogFont=lf
  3857. cf.Flags=CF_BOTH
  3858. If font
  3859. Local p:Short Ptr = Short Ptr(Varptr lf.lfFaceName00)
  3860. For Local i = 0 Until Min(font.name.length, 31)
  3861. p[i]=font.name[i]
  3862. Next
  3863. SetLogFontProperties( lf, font.style, font.size )
  3864. cf.Flags:|CF_INITTOLOGFONTSTRUCT
  3865. EndIf
  3866. Local hwnd = GetFocus()
  3867. Local n = ChooseFontW(cf)
  3868. SetFocus(hwnd)
  3869. If Not n Return
  3870. Local style
  3871. If cf.nFontType&BOLD_FONTTYPE style:|FONT_BOLD
  3872. If cf.nFontType&ITALIC_FONTTYPE style:|FONT_ITALIC
  3873. Return New TWindowsFont.LoadFromLogFont( lf, style, cf.iPointSize/Double(10) )
  3874. EndFunction
  3875. Function DefaultFont:TWindowsFont( pFontSize:Double = 0, pFontStyle% = FONT_NORMAL )
  3876. 'Attempts to get hold of the Windows themed font (typically Tahoma on XP, Segeo UI on Vista)
  3877. Local tmpNonClientMetrics:NONCLIENTMETRICSW = New NONCLIENTMETRICSW
  3878. If SystemParametersInfoW And SystemParametersInfoW( SPI_GETNONCLIENTMETRICS, 0, Int Byte Ptr tmpNonClientMetrics, 0 ) Then
  3879. Local tmpLogFont:LOGFONTW = New LOGFONTW
  3880. MemCopy tmpLogFont, Varptr tmpNonClientMetrics.lfMessageFont_lfHeight, SizeOf(tmpLogFont)
  3881. Return New TWindowsFont.LoadFromLogFont( tmpLogFont, pFontStyle, pFontSize )
  3882. EndIf
  3883. 'If these functions, for whatever reason, fail, then the default GUI font is used (typically MS Sans Serif).
  3884. 'Note: A font size of '8' has has been hard-coded in as no reliable substitute can be found, however this may cause
  3885. 'text to appear too small in some languages/lacalizations.
  3886. If pFontSize <= 0 Then pFontSize = 8
  3887. Return New TWindowsFont.Load( "MS Shell Dlg", pFontSize, pFontStyle )
  3888. EndFunction
  3889. Function NameFromHandle:String( pFntHandle:Int )
  3890. Local hdc = GetDC(0), buffer:Short[512]
  3891. Local tfont = SelectObject(hdc,pFntHandle)
  3892. If Not GetTextFaceW(hdc,buffer.length,buffer) buffer[0] = 0
  3893. SelectObject(hdc, tfont)
  3894. ReleaseDC(0,hdc)
  3895. Return String.FromWString(buffer)
  3896. EndFunction
  3897. Function LogicalUnitsFromSize( pSize:Double )
  3898. Local tmpDC:Int = GetDC(0)
  3899. Local tmpSize:Int = (pSize * GetDeviceCaps(tmpDC,LOGPIXELSY))/72 + 0.5
  3900. ReleaseDC( 0, tmpDC )
  3901. Return tmpSize
  3902. EndFunction
  3903. Function SizeFromLogFont:Double( pLogFont:LOGFONTW )
  3904. Local tmpDC:Int = GetDC(0)
  3905. Local tmpSize:Double = (Abs(pLogFont.lfHeight) * Double(72.0) )/GetDeviceCaps(tmpDC,LOGPIXELSY)
  3906. ReleaseDC( 0, tmpDC )
  3907. Return tmpSize
  3908. EndFunction
  3909. Function SetLogFontProperties( pLogFont:LOGFONTW, pFlags%, pSize:Double = 0:Double )
  3910. If pFlags&FONT_BOLD Then pLogFont.lfWeight=FW_BOLD Else pLogFont.lfWeight=FW_NORMAL
  3911. If pFlags&FONT_ITALIC Then pLogFont.lfItalic=True Else pLogFont.lfItalic=False
  3912. If pFlags&FONT_UNDERLINE Then pLogFont.lfUnderline=True Else pLogFont.lfUnderline=False
  3913. If pFlags&FONT_STRIKETHROUGH Then pLogFont.lfStrikeOut=True Else pLogFont.lfStrikeOut=False
  3914. If pSize > 0 Then pLogFont.lfHeight = -LogicalUnitsFromSize( pSize )
  3915. EndFunction
  3916. EndType
  3917. 'A collection of functions that convert between Blitz pixmaps and Windows icons/bitmaps.
  3918. Type TWindowsGraphic Final
  3919. Function BitmapMaskFromPixmap:Int(pix:TPixmap)
  3920. Local x, pix2:TPixmap, usealpha
  3921. If PixmapFormat(pix) = PF_RGBA8888 Or PixmapFormat(pix) = PF_BGRA8888 Then usealpha = True
  3922. pix2=ConvertPixmap(pix,PF_BGR888);ClearPixels(pix2)
  3923. For Local y:Int = 0 Until pix.height
  3924. For x = 0 Until pix.width
  3925. If usealpha
  3926. If (ReadPixel(pix,x,y) Shr 24) < 128 Then WritePixel(pix2,x,y,$FFFFFF)
  3927. Else
  3928. If (ReadPixel(pix,x,y) & $FFFFFF) = $FFFFFF Then WritePixel(pix2,x,y,$FFFFFF)
  3929. EndIf
  3930. Next
  3931. Next
  3932. Return BitmapFromPixmap(pix2,False)
  3933. EndFunction
  3934. Function PreMultipliedBitmapFromPixmap32:Int( pix:TPixmap )
  3935. Local argb, a
  3936. Local pix2:TPixmap = CreatePixmap( pix.width, pix.height, pix.format), x
  3937. For Local y:Int = 0 Until pix.height
  3938. For x = 0 Until pix.width
  3939. argb = ReadPixel(pix,x,y)
  3940. a = ((argb Shr 24) & $FF)
  3941. WritePixel(pix2,x,y,((((argb&$ff00ff)*a)Shr 8)&$ff00ff)|((((argb&$ff00)*a)Shr 8)&$ff00)|(a Shl 24))
  3942. Next
  3943. Next
  3944. Return BitmapFromPixmap(pix2,True)
  3945. EndFunction
  3946. Function BitmapFromPixmap:Int(pix:TPixmap, alpha:Int = True)
  3947. Local bitCount:Int = 32, format:Int = PF_BGRA8888, bm
  3948. If Not alpha Then
  3949. bitCount = 24
  3950. format = PF_BGR888
  3951. EndIf
  3952. pix=ConvertPixmap(pix,format)
  3953. Local hdc = GetDC(0)
  3954. Local bi:BITMAPINFOHEADER = New BITMAPINFOHEADER
  3955. bi.biSize=SizeOf(bi)
  3956. bi.biWidth=pix.width
  3957. bi.biHeight=-pix.height
  3958. bi.biPlanes=1
  3959. bi.biBitCount=bitCount
  3960. bi.biCompression=BI_RGB
  3961. Local bits:Byte Ptr
  3962. Local src:Byte Ptr = pix.pixels
  3963. If alpha
  3964. bm = CreateDibSection(hdc,bi,DIB_RGB_COLORS,Varptr bits,0,0)
  3965. Else
  3966. bm = CreateCompatibleBitmap(hdc,pix.width,pix.height)
  3967. EndIf
  3968. Assert bm, "Cannot create bitmap. The computer may be running low on resources."
  3969. For Local y:Int = 0 Until pix.height
  3970. SetDIBits(hdc,bm,pix.height-y-1,1,src,bi,DIB_RGB_COLORS)
  3971. src:+pix.pitch
  3972. Next
  3973. ReleaseDC(0,hdc)
  3974. Return bm
  3975. EndFunction
  3976. Function BitmapWithBackgroundFromPixmap32:Int( pix:TPixmap, pRed, pGreen, pBlue )
  3977. Local tmpPixel, tmpRed, tmpGreen, tmpBlue, tmpAlpha, tmpAlphaFloat#, tmpAlphaFloat2#
  3978. Local pix2:TPixmap = CreatePixmap( pix.width, pix.height, pix.format), x
  3979. For Local y:Int = 0 Until pix.height
  3980. For x = 0 Until pix.width
  3981. 'Read pixel and alpha info
  3982. tmpPixel = ReadPixel(pix,x,y)
  3983. tmpAlpha = ((tmpPixel Shr 24) & $FF)
  3984. tmpAlphaFloat = tmpAlpha/255.0
  3985. tmpAlphaFloat2 = 1-tmpAlphaFloat
  3986. 'Get individual colours
  3987. tmpBlue = tmpPixel & $FF;tmpGreen = (tmpPixel Shr 8) & $FF;tmpRed = (tmpPixel Shr 16)&$FF
  3988. 'Courtesy of Mark T
  3989. tmpRed = (tmpRed * tmpAlphaFloat) + (tmpAlphaFloat2 * pRed)
  3990. tmpGreen = (tmpGreen * tmpAlphaFloat) + (tmpAlphaFloat2 * pGreen)
  3991. tmpBlue = (tmpBlue * tmpAlphaFloat) + (tmpAlphaFloat2 * pBlue)
  3992. 'Write the new pixels
  3993. WritePixel(pix2,x,y,(tmpAlpha Shl 24)|(tmpRed Shl 16)|(tmpGreen Shl 8)|tmpBlue)
  3994. Next
  3995. Next
  3996. Return BitmapFromPixmap(pix2,False)
  3997. EndFunction
  3998. Function IconFromPixmap32:Int(pix:TPixmap)
  3999. ' Convert the pixmap to a HBITMAP
  4000. Local bitmap = BitmapFromPixmap(pix,True)
  4001. ' and then copy/resize it (to the default size for icons/cusors).
  4002. Local hSrcBMP = CopyImage(bitmap, IMAGE_BITMAP , 0 , 0 , LR_DEFAULTSIZE)
  4003. ' Now we need to create a mask bitmap for the image
  4004. Local hMaskBMP = BitmapMaskFromPixmap( pix )
  4005. ' So now we have our source and mask bitmaps, we can create an ICONINFO structure
  4006. Local IconInf:ICONINFO = New IconInfo
  4007. IconInf.fIcon = True
  4008. IconInf.hbmMask = hMaskBMP
  4009. IconInf.hbmColor = hSrcBMP
  4010. ' Create the icon
  4011. Local tmpIcon = CreateIconIndirect(IconInf)
  4012. ' Free our temporary bitmaps
  4013. DeleteObject(hMaskBMP)
  4014. DeleteObject(hSrcBMP)
  4015. DeleteObject(bitmap)
  4016. Return tmpIcon
  4017. EndFunction
  4018. EndType
  4019. Private
  4020. Function KeyMods()
  4021. Local mods
  4022. If GetKeyState(VK_SHIFT)&$8000 mods:|MODIFIER_SHIFT
  4023. If GetKeyState(VK_CONTROL)&$8000 mods:|MODIFIER_CONTROL
  4024. If GetKeyState(VK_MENU)&$8000 mods:|MODIFIER_OPTION
  4025. If GetKeyState(VK_LWIN)&$8000 Or GetKeyState(VK_RWIN)&$8000 mods:|MODIFIER_SYSTEM
  4026. Return mods
  4027. EndFunction
  4028. Function FindGadgetWindowHwnd(g:TGadget)
  4029. Local wg:TWindowsWindow
  4030. While g
  4031. wg=TWindowsWindow(g)
  4032. If wg Return wg.Query(QUERY_HWND) 'handle
  4033. g=g.parent
  4034. Wend
  4035. EndFunction
  4036. Type TIntWrapper Final
  4037. Field value:Int
  4038. Function Create:TIntWrapper(value:Int)
  4039. Local tmpWrapper:TIntWrapper = New TIntWrapper
  4040. tmpWrapper.value = value
  4041. Return tmpWrapper
  4042. EndFunction
  4043. Method Compare( o:Object )
  4044. Local c:TIntWrapper = TIntWrapper(o)
  4045. If c Then Return (value - c.value)
  4046. Return Super.Compare(o)
  4047. EndMethod
  4048. Method ToString$()
  4049. Return value
  4050. EndMethod
  4051. EndType