PropertyGrid.cpp 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474
  1. // PropertyGrid.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "CustomItem.h"
  5. #include "PropertyGrid.h"
  6. #include "PropertyGridDirectoryPicker.h"
  7. #include "PropertyGridMonthCalCtrl.h"
  8. #include "DynDialogEx.h"
  9. #include <algorithm>
  10. #include <shlwapi.h>
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16. #define IDC_MONTHCAL 1023
  17. //CheckBox data
  18. static const int CheckBoxHeight = 13;
  19. int Item_CheckOn[169] =
  20. {
  21. 0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,
  22. 0x1c5180,0xe2e2dd,0xe2e2dd,0xe2e2dd,0xe3e3df,0xe5e5e1,0xe7e7e3,0xeaeae6,0xecece9,0xefefec,0xf1f1ef,0xf3f3f1,0x1c5180,
  23. 0x1c5180,0xe2e2dd,0xe2e2dd,0xe3e3df,0xe5e5e1,0xe7e7e3,0xeaeae6,0xecece9,0xefefec,0xf1f1ef,0xf3f3f1,0xf5f5f3,0x1c5180,
  24. 0x1c5180,0xe2e2dd,0xe3e3df,0xe5e5e1,0xe7e7e3,0xeaeae6,0xecece9,0xefefec,0xf1f1ef,0x21a121,0xf5f5f3,0xf7f7f6,0x1c5180,
  25. 0x1c5180,0xe3e3df,0xe5e5e1,0xe7e7e3,0xeaeae6,0xecece9,0xefefec,0xf1f1ef,0x21a121,0x21a121,0xf7f7f6,0xf9f9f8,0x1c5180,
  26. 0x1c5180,0xe5e5e1,0xe7e7e3,0x21a121,0xecece9,0xefefec,0xf1f1ef,0x21a121,0x21a121,0x21a121,0xf9f9f8,0xfafaf9,0x1c5180,
  27. 0x1c5180,0xe7e7e3,0xeaeae6,0x21a121,0x21a121,0xf1f1ef,0x21a121,0x21a121,0x21a121,0xf9f9f8,0xfafaf9,0xfcfcfb,0x1c5180,
  28. 0x1c5180,0xeaeae6,0xecece9,0x21a121,0x21a121,0x21a121,0x21a121,0x21a121,0xf9f9f8,0xfafaf9,0xfcfcfb,0xfdfdfd,0x1c5180,
  29. 0x1c5180,0xecece9,0xefefec,0xf1f1ef,0x21a121,0x21a121,0x21a121,0xf9f9f8,0xfafaf9,0xfcfcfb,0xfdfdfd,0xfefefe,0x1c5180,
  30. 0x1c5180,0xefefec,0xf1f1ef,0xf3f3f1,0xf5f5f3,0x21a121,0xf9f9f8,0xfafaf9,0xfcfcfb,0xfdfdfd,0xfefefe,0xffffff,0x1c5180,
  31. 0x1c5180,0xf1f1ef,0xf3f3f1,0xf5f5f3,0xf7f7f6,0xf9f9f8,0xfafaf9,0xfcfcfb,0xfdfdfd,0xfefefe,0xffffff,0xffffff,0x1c5180,
  32. 0x1c5180,0xf3f3f1,0xf5f5f3,0xf7f7f6,0xf9f9f8,0xfafaf9,0xfcfcfb,0xfdfdfd,0xfefefe,0xffffff,0xffffff,0xffffff,0x1c5180,
  33. 0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,
  34. };
  35. int Item_CheckOff[169] =
  36. {
  37. 0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,
  38. 0x1c5180,0xdcdcd7,0xdcdcd7,0xdcdcd7,0xdeded9,0xe0e0db,0xe2e2de,0xe5e5e2,0xe8e8e5,0xecece9,0xefefec,0xf1f1ef,0x1c5180,
  39. 0x1c5180,0xdcdcd7,0xdcdcd7,0xdeded9,0xe0e0db,0xe2e2de,0xe5e5e2,0xe8e8e5,0xecece9,0xefefec,0xf1f1ef,0xf3f3f1,0x1c5180,
  40. 0x1c5180,0xdcdcd7,0xdeded9,0xe0e0db,0xe2e2de,0xe5e5e2,0xe8e8e5,0xecece9,0xefefec,0xf1f1ef,0xf3f3f1,0xf5f5f4,0x1c5180,
  41. 0x1c5180,0xdeded9,0xe0e0db,0xe2e2de,0xe5e5e2,0xe8e8e5,0xecece9,0xefefec,0xf1f1ef,0xf3f3f1,0xf5f5f4,0xf7f7f6,0x1c5180,
  42. 0x1c5180,0xe0e0db,0xe2e2de,0xe5e5e2,0xe8e8e5,0xecece9,0xefefec,0xf1f1ef,0xf3f3f1,0xf5f5f4,0xf7f7f6,0xf9f9f8,0x1c5180,
  43. 0x1c5180,0xe2e2de,0xe5e5e2,0xe8e8e5,0xecece9,0xefefec,0xf1f1ef,0xf3f3f1,0xf5f5f4,0xf7f7f6,0xf9f9f8,0xfbfbfa,0x1c5180,
  44. 0x1c5180,0xe5e5e2,0xe8e8e5,0xecece9,0xefefec,0xf1f1ef,0xf3f3f1,0xf5f5f4,0xf7f7f6,0xf9f9f8,0xfbfbfa,0xfdfdfc,0x1c5180,
  45. 0x1c5180,0xe8e8e5,0xecece9,0xefefec,0xf1f1ef,0xf3f3f1,0xf5f5f4,0xf7f7f6,0xf9f9f8,0xfbfbfa,0xfdfdfc,0xfefefe,0x1c5180,
  46. 0x1c5180,0xecece9,0xefefec,0xf1f1ef,0xf3f3f1,0xf5f5f4,0xf7f7f6,0xf9f9f8,0xfbfbfa,0xfdfdfc,0xfefefe,0xffffff,0x1c5180,
  47. 0x1c5180,0xefefec,0xf1f1ef,0xf3f3f1,0xf5f5f4,0xf7f7f6,0xf9f9f8,0xfbfbfa,0xfdfdfc,0xfefefe,0xffffff,0xffffff,0x1c5180,
  48. 0x1c5180,0xf1f1ef,0xf3f3f1,0xf5f5f4,0xf7f7f6,0xf9f9f8,0xfbfbfa,0xfdfdfc,0xfefefe,0xffffff,0xffffff,0xffffff,0x1c5180,
  49. 0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,0x1c5180,
  50. };
  51. int Item_CheckOn_Disabled[] =
  52. {
  53. 0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,
  54. 0xcac8bb,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xcac8bb,
  55. 0xcac8bb,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xcac8bb,
  56. 0xcac8bb,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xcac8bb,0xffffff,0xffffff,0xcac8bb,
  57. 0xcac8bb,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xcac8bb,0xcac8bb,0xffffff,0xffffff,0xcac8bb,
  58. 0xcac8bb,0xffffff,0xffffff,0xcac8bb,0xffffff,0xffffff,0xffffff,0xcac8bb,0xcac8bb,0xcac8bb,0xffffff,0xffffff,0xcac8bb,
  59. 0xcac8bb,0xffffff,0xffffff,0xcac8bb,0xcac8bb,0xffffff,0xcac8bb,0xcac8bb,0xcac8bb,0xffffff,0xffffff,0xffffff,0xcac8bb,
  60. 0xcac8bb,0xffffff,0xffffff,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xffffff,0xffffff,0xffffff,0xffffff,0xcac8bb,
  61. 0xcac8bb,0xffffff,0xffffff,0xffffff,0xcac8bb,0xcac8bb,0xcac8bb,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xcac8bb,
  62. 0xcac8bb,0xffffff,0xffffff,0xffffff,0xffffff,0xcac8bb,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xcac8bb,
  63. 0xcac8bb,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xcac8bb,
  64. 0xcac8bb,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xcac8bb,
  65. 0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,
  66. };
  67. int Item_CheckOff_Disabled[] =
  68. {
  69. 0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,
  70. 0xcac8bb,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xcac8bb,
  71. 0xcac8bb,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xcac8bb,
  72. 0xcac8bb,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xcac8bb,
  73. 0xcac8bb,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xcac8bb,
  74. 0xcac8bb,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xcac8bb,
  75. 0xcac8bb,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xcac8bb,
  76. 0xcac8bb,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xcac8bb,
  77. 0xcac8bb,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xcac8bb,
  78. 0xcac8bb,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xcac8bb,
  79. 0xcac8bb,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xcac8bb,
  80. 0xcac8bb,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xcac8bb,
  81. 0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,0xcac8bb,
  82. };
  83. // CPropertyGrid
  84. static const int margin = 2;
  85. IMPLEMENT_DYNAMIC(CPropertyGrid, CWnd)
  86. CPropertyGrid::CPropertyGrid()
  87. {
  88. m_section_id = 0;
  89. m_item_id = 0;
  90. m_resizing_gutter = false;
  91. m_button_pushed = false;
  92. m_button_depressed = false;
  93. m_value_clicked = false;
  94. m_custom_tracking = false;
  95. m_scroll_enabled = false;
  96. m_draw_lines = true;
  97. m_shade_titles = true;
  98. m_draw_gutter = true;
  99. m_focus_disabled = true;
  100. m_bold_modified = false;
  101. m_bold_editables = false;
  102. m_display_mode = DM_CATEGORIZED;
  103. m_control = NULL;
  104. m_rect_button = CRect(0,0,0,0);
  105. m_ptLast = CPoint(0,0);
  106. m_strTrue = "True";
  107. m_strFalse = "False";
  108. m_strDate = "Date";
  109. m_strTime = "Time";
  110. m_strUndefined = "";
  111. m_strEmpty = "";
  112. m_clrBack = GetSysColor(COLOR_WINDOW);
  113. m_clrShade = GetSysColor(COLOR_3DFACE);
  114. m_clrText = GetSysColor(COLOR_WINDOWTEXT);
  115. m_clrTitle = GetSysColor(COLOR_WINDOWTEXT);
  116. m_clrFocus = GetSysColor(COLOR_HIGHLIGHT);
  117. m_clrHilite = GetSysColor(COLOR_HIGHLIGHTTEXT);
  118. m_clrEditable = GetSysColor(COLOR_WINDOWTEXT);
  119. m_clrDisabled = GetSysColor(COLOR_GRAYTEXT);
  120. m_focused_section = -1;
  121. m_focused_item = -1;
  122. }
  123. CPropertyGrid::~CPropertyGrid()
  124. {
  125. }
  126. //
  127. // customization
  128. //
  129. bool CPropertyGrid::GetShadeTitles()
  130. {
  131. return m_shade_titles;
  132. }
  133. void CPropertyGrid::SetShadeTitles(bool shade_titles)
  134. {
  135. m_shade_titles = shade_titles;
  136. if (GetSafeHwnd())
  137. Invalidate();
  138. }
  139. bool CPropertyGrid::GetDrawLines()
  140. {
  141. return m_draw_lines;
  142. }
  143. void CPropertyGrid::SetDrawLines(bool draw_lines)
  144. {
  145. m_draw_lines = draw_lines;
  146. if (GetSafeHwnd())
  147. Invalidate();
  148. }
  149. bool CPropertyGrid::GetDrawGutter()
  150. {
  151. return m_draw_gutter;
  152. }
  153. void CPropertyGrid::SetDrawGutter(bool draw_gutter)
  154. {
  155. m_draw_gutter = draw_gutter;
  156. if (GetSafeHwnd())
  157. Invalidate();
  158. }
  159. bool CPropertyGrid::GetFocusDisabled()
  160. {
  161. return m_focus_disabled;
  162. }
  163. void CPropertyGrid::SetFocusDisabled(bool focus_disabled)
  164. {
  165. m_focus_disabled = focus_disabled;
  166. if (GetSafeHwnd())
  167. Invalidate();
  168. }
  169. bool CPropertyGrid::GetBoldModified()
  170. {
  171. return m_bold_modified;
  172. }
  173. void CPropertyGrid::SetBoldModified(bool bold_modified)
  174. {
  175. m_bold_modified = bold_modified;
  176. }
  177. bool CPropertyGrid::GetBoldEditables()
  178. {
  179. return m_bold_editables;
  180. }
  181. void CPropertyGrid::SetBoldEditables(bool bold_editables)
  182. {
  183. m_bold_editables = bold_editables;
  184. }
  185. //
  186. // gutter width
  187. //
  188. int CPropertyGrid::GetGutterWidth()
  189. {
  190. return m_gutter_width;
  191. }
  192. void CPropertyGrid::SetGutterWidth(int gutter_width)
  193. {
  194. m_gutter_width = gutter_width;
  195. if (GetSafeHwnd())
  196. Invalidate();
  197. }
  198. //
  199. // custom colors
  200. //
  201. void CPropertyGrid::SetTextColor(COLORREF clrText)
  202. {
  203. if (m_clrText == m_clrEditable)
  204. m_clrEditable = clrText;
  205. m_clrText = clrText;
  206. if (GetSafeHwnd())
  207. Invalidate();
  208. }
  209. void CPropertyGrid::SetTitleColor(COLORREF clrTitle)
  210. {
  211. m_clrTitle = clrTitle;
  212. if (GetSafeHwnd())
  213. Invalidate();
  214. }
  215. void CPropertyGrid::SetBackColor(COLORREF clrBack)
  216. {
  217. m_clrBack = clrBack;
  218. if (GetSafeHwnd())
  219. Invalidate();
  220. }
  221. void CPropertyGrid::SetShadeColor(COLORREF clrShade)
  222. {
  223. m_clrShade = clrShade;
  224. if (GetSafeHwnd())
  225. Invalidate();
  226. }
  227. void CPropertyGrid::SetFocusColor(COLORREF clrFocus)
  228. {
  229. m_clrFocus = clrFocus;
  230. if (GetSafeHwnd())
  231. Invalidate();
  232. }
  233. void CPropertyGrid::SetHiliteColor(COLORREF clrHilite)
  234. {
  235. m_clrHilite = clrHilite;
  236. if (GetSafeHwnd())
  237. Invalidate();
  238. }
  239. void CPropertyGrid::SetEditableColor(COLORREF clrEditable)
  240. {
  241. m_clrEditable = clrEditable;
  242. if (GetSafeHwnd())
  243. Invalidate();
  244. }
  245. void CPropertyGrid::SetDisabledColor(COLORREF clrDisabled)
  246. {
  247. m_clrDisabled = clrDisabled;
  248. if (GetSafeHwnd())
  249. Invalidate();
  250. }
  251. //
  252. // localization
  253. //
  254. void CPropertyGrid::SetTrueFalseStrings(string strTrue, string strFalse)
  255. {
  256. m_strTrue = strTrue;
  257. m_strFalse = strFalse;
  258. }
  259. void CPropertyGrid::SetOkCancelStrings(string strOk, string strCancel)
  260. {
  261. m_strOk = strOk;
  262. m_strCancel = strCancel;
  263. }
  264. void CPropertyGrid::SetDateTimeStrings(string strDate, string strTime)
  265. {
  266. m_strDate = strDate;
  267. m_strTime = strTime;
  268. }
  269. void CPropertyGrid::SetUndefinedString(string strUndefined)
  270. {
  271. m_strUndefined = strUndefined;
  272. }
  273. void CPropertyGrid::SetEmptyString(string strEmpty)
  274. {
  275. m_strEmpty = strEmpty;
  276. }
  277. //
  278. // appearance
  279. //
  280. void CPropertyGrid::SetDisplayMode(EDisplayMode display_mode)
  281. {
  282. m_display_mode = display_mode;
  283. RecalcLayout();
  284. }
  285. void CPropertyGrid::ExpandAll(bool expand)
  286. {
  287. for (vector<CSection>::iterator it = m_sections.begin(); it != m_sections.end(); ++it)
  288. it->m_collapsed = !expand;
  289. RecalcLayout();
  290. }
  291. void CPropertyGrid::ExpandSection(HSECTION hs, bool expand)
  292. {
  293. CSection* pSection = FindSection(hs);
  294. if (pSection)
  295. {
  296. pSection->m_collapsed = !expand;
  297. RecalcLayout();
  298. }
  299. }
  300. bool CPropertyGrid::IsSectionCollapsed(HSECTION hs)
  301. {
  302. CSection* pSection = FindSection(hs);
  303. if (pSection)
  304. return pSection->m_collapsed;
  305. return false;
  306. }
  307. //
  308. // item management
  309. //
  310. bool CPropertyGrid::CItem::operator==(const HITEM& item) const
  311. {
  312. return m_id == item;
  313. }
  314. bool CPropertyGrid::CItem::operator==(const string& name) const
  315. {
  316. return m_name == name;
  317. }
  318. bool CPropertyGrid::CSection::operator==(const HSECTION& section) const
  319. {
  320. return m_id == section;
  321. }
  322. void CPropertyGrid::CItem::ValidateChanges()
  323. {
  324. // save the values
  325. m_undefined_old = m_undefined;
  326. m_nValue_old = m_nValue;
  327. m_dValue_old = m_dValue;
  328. m_strValue_old = m_strValue;
  329. m_bValue_old = m_bValue;
  330. m_dtValue_old = m_dtValue;
  331. m_clrValue_old = m_clrValue;
  332. memcpy(&m_lfValue_old, &m_lfValue, sizeof(LOGFONT));
  333. // callback for custom
  334. if (m_type == IT_CUSTOM)
  335. m_pCustom->ValidateChanges();
  336. }
  337. HSECTION CPropertyGrid::AddSection(string title, bool collapsed, HSECTION after)
  338. {
  339. // build it
  340. CSection section;
  341. section.m_id = m_section_id;
  342. section.m_title = title;
  343. section.m_collapsed = collapsed;
  344. // insert it
  345. // if after does not exist then it is appended
  346. vector<CSection>::iterator it = find(m_sections.begin(), m_sections.end(), after);
  347. m_sections.insert(it, section);
  348. // done
  349. RecalcLayout();
  350. return m_section_id++;
  351. }
  352. HITEM CPropertyGrid::AddItem(HSECTION hs, EItemType type, string name, void* pValue, bool editable, bool undefined, HITEM after)
  353. {
  354. // check section exists
  355. vector<CSection>::iterator it = find(m_sections.begin(), m_sections.end(), hs);
  356. if (it == m_sections.end())
  357. return -1;
  358. // check item does not already exists
  359. vector<CItem>::iterator it2 = find(it->m_items.begin(), it->m_items.end(), name);
  360. if (it2 != it->m_items.end())
  361. return -1;
  362. // build the item
  363. CItem item;
  364. item.m_id = m_item_id++;
  365. item.m_type = type;
  366. item.m_name = name;
  367. item.m_editable = editable;
  368. item.m_undefined = undefined;
  369. // assign the value
  370. if (type == IT_CUSTOM) item.m_pCustom = (ICustomItem*)pValue;
  371. else if (type == IT_STRING || type == IT_TEXT || type == IT_FILE || type == IT_FOLDER) item.m_strValue = *(string*)pValue;
  372. else if (type == IT_COMBO || type == IT_INTEGER) item.m_nValue = *(int*)pValue;
  373. else if (type == IT_DOUBLE) item.m_dValue = *(double*)pValue;
  374. else if (type == IT_BOOLEAN || type == IT_CHECK ) item.m_bValue = *(bool*)pValue;
  375. else if (type == IT_DATE || type == IT_DATETIME) item.m_dtValue = *(COleDateTime*)pValue;
  376. else if (type == IT_COLOR) item.m_clrValue = *(COLORREF*)pValue;
  377. else if (type == IT_FONT) memcpy(&item.m_lfValue, pValue, sizeof(LOGFONT));
  378. else assert(false);
  379. // finish and add
  380. item.ValidateChanges();
  381. it->m_items.push_back(item);
  382. RecalcLayout();
  383. return item.m_id;
  384. }
  385. HITEM CPropertyGrid::AddCustomItem(HSECTION section, string name, ICustomItem* pItem, bool editable, HITEM after)
  386. {
  387. pItem->m_pGrid = this;
  388. return AddItem(section, IT_CUSTOM, name, pItem, editable, false, after);
  389. }
  390. HITEM CPropertyGrid::AddStringItem(HSECTION section, string name, string value, bool editable, HITEM after)
  391. {
  392. return AddItem(section, IT_STRING, name, &value, editable, false, after);
  393. }
  394. HITEM CPropertyGrid::AddTextItem(HSECTION section, string name, string value, bool editable, HITEM after)
  395. {
  396. return AddItem(section, IT_TEXT, name, &value, editable, false, after);
  397. }
  398. HITEM CPropertyGrid::AddIntegerItem(HSECTION section, string name, int value, string format, bool editable, bool undefined, HITEM after)
  399. {
  400. HITEM it = AddItem(section, IT_INTEGER, name, &value, editable, undefined, after);
  401. CItem* pItem = FindItem(it);
  402. if (pItem) pItem->m_options.push_back(format);
  403. return it;
  404. }
  405. HITEM CPropertyGrid::AddDoubleItem(HSECTION section, string name, double value, string format, bool editable, bool undefined, HITEM after)
  406. {
  407. HITEM it = AddItem(section, IT_DOUBLE, name, &value, editable, undefined, after);
  408. CItem* pItem = FindItem(it);
  409. if (pItem) pItem->m_options.push_back(format);
  410. return it;
  411. }
  412. HITEM CPropertyGrid::AddComboItem(HSECTION section, string name, const vector<string>& values, int cur, bool editable, bool undefined, HITEM after)
  413. {
  414. HITEM it = AddItem(section, IT_COMBO, name, &cur, editable, undefined, after);
  415. CItem* pItem = FindItem(it);
  416. if (pItem) pItem->m_options = values;
  417. return it;
  418. }
  419. HITEM CPropertyGrid::AddBoolItem(HSECTION section, string name, bool value, bool editable, bool undefined, HITEM after)
  420. {
  421. return AddItem(section, IT_BOOLEAN, name, &value, editable, undefined, after);
  422. }
  423. HITEM CPropertyGrid::AddDateItem(HSECTION section, string name, COleDateTime value, string format, bool editable, bool undefined, HITEM after)
  424. {
  425. HITEM it = AddItem(section, IT_DATE, name, &value, editable, undefined, after);
  426. CItem* pItem = FindItem(it);
  427. if (pItem) pItem->m_options.push_back(format);
  428. return it;
  429. }
  430. HITEM CPropertyGrid::AddDateTimeItem(HSECTION section, string name, COleDateTime value, string format, bool editable, bool undefined, HITEM after)
  431. {
  432. HITEM it = AddItem(section, IT_DATETIME, name, &value, editable, undefined, after);
  433. CItem* pItem = FindItem(it);
  434. if (pItem) pItem->m_options.push_back(format);
  435. return it;
  436. }
  437. HITEM CPropertyGrid::AddFileItem(HSECTION section, string name, string value, string filter, bool editable, HITEM after)
  438. {
  439. HITEM it = AddItem(section, IT_FILE, name, &value, editable, false, after);
  440. CItem* pItem = FindItem(it);
  441. if (pItem) pItem->m_options.push_back(filter);
  442. return it;
  443. }
  444. HITEM CPropertyGrid::AddFolderItem(HSECTION section, string name, string value, string title, bool editable, HITEM after)
  445. {
  446. HITEM it = AddItem(section, IT_FOLDER, name, &value, editable, false, after);
  447. CItem* pItem = FindItem(it);
  448. if (pItem) pItem->m_options.push_back(title);
  449. return it;
  450. }
  451. HITEM CPropertyGrid::AddColorItem(HSECTION section, string name, COLORREF value, bool editable, bool undefined, HITEM after)
  452. {
  453. return AddItem(section, IT_COLOR, name, &value, editable, undefined, after);
  454. }
  455. HITEM CPropertyGrid::AddFontItem(HSECTION section, string name, LOGFONT value, bool editable, bool undefined, HITEM after)
  456. {
  457. return AddItem(section, IT_FONT, name, &value, editable, undefined, after);
  458. }
  459. void CPropertyGrid::ResetContents()
  460. {
  461. m_sections.clear();
  462. m_section_id = 0;
  463. m_item_id = 0;
  464. RecalcLayout();
  465. }
  466. bool CPropertyGrid::RemoveSection(HSECTION hs)
  467. {
  468. vector<CSection>::iterator it = find(m_sections.begin(), m_sections.end(), hs);
  469. if (it == m_sections.end()) return false;
  470. m_sections.erase(it);
  471. return true;
  472. }
  473. bool CPropertyGrid::RemoveItem(HITEM item)
  474. {
  475. for (vector<CSection>::iterator it = m_sections.begin(); it != m_sections.end(); ++it)
  476. {
  477. vector<CItem>::iterator it2 = find(it->m_items.begin(), it->m_items.end(), item);
  478. if (it2 != it->m_items.end())
  479. {
  480. it->m_items.erase(it2);
  481. return true;
  482. }
  483. }
  484. return false;
  485. }
  486. int CPropertyGrid::GetNumSections()
  487. {
  488. return int(m_sections.size());
  489. }
  490. int CPropertyGrid::GetSectionSize(HSECTION hs)
  491. {
  492. CSection* pSection = FindSection(hs);
  493. if (pSection) return int(pSection->m_items.size());
  494. return 0;
  495. }
  496. void CPropertyGrid::ValidateChanges()
  497. {
  498. for (vector<CSection>::iterator it = m_sections.begin(); it != m_sections.end(); ++it)
  499. {
  500. for (vector<CItem>::iterator it2 = it->m_items.begin(); it2 != it->m_items.end(); ++it2)
  501. it2->ValidateChanges();
  502. }
  503. }
  504. CPropertyGrid::CSection* CPropertyGrid::FindSection(HSECTION hs) const
  505. {
  506. vector<CSection>::const_iterator it = find(m_sections.begin(), m_sections.end(), hs);
  507. if (it == m_sections.end()) return NULL;
  508. return const_cast<CSection*>(&(*it));
  509. }
  510. CPropertyGrid::CItem* CPropertyGrid::FindItem(HITEM hi) const
  511. {
  512. for (vector<CSection>::const_iterator it = m_sections.begin(); it != m_sections.end(); ++it)
  513. {
  514. vector<CItem>::const_iterator it2 = find(it->m_items.begin(), it->m_items.end(), hi);
  515. if (it2 != it->m_items.end())
  516. return const_cast<CItem*>(&(*it2));
  517. }
  518. return NULL;
  519. }
  520. bool CPropertyGrid::GetItemValue(HITEM item, string& strValue) const
  521. {
  522. // get the item
  523. CItem* pItem = FindItem(item);
  524. if (pItem == NULL) return false;
  525. if (pItem->m_undefined) return false;
  526. // check
  527. if (pItem->m_type == IT_STRING || pItem->m_type == IT_TEXT || pItem->m_type == IT_FILE || pItem->m_type == IT_FOLDER)
  528. {
  529. strValue = pItem->m_strValue;
  530. return true;
  531. }
  532. else if (pItem->m_type == IT_COMBO)
  533. {
  534. if (pItem->m_nValue < 0 || pItem->m_nValue > int(pItem->m_options.size())-1) return false;
  535. strValue = pItem->m_options[pItem->m_nValue];
  536. return true;
  537. }
  538. return false;
  539. }
  540. bool CPropertyGrid::GetItemValue(HITEM item, int& nValue) const
  541. {
  542. // get the item
  543. CItem* pItem = FindItem(item);
  544. if (pItem == NULL) return false;
  545. if (pItem->m_undefined) return false;
  546. // check
  547. if (pItem->m_type == IT_COMBO || pItem->m_type == IT_INTEGER)
  548. {
  549. nValue = pItem->m_nValue;
  550. return true;
  551. }
  552. return false;
  553. }
  554. bool CPropertyGrid::GetItemValue(HITEM item, double& dValue) const
  555. {
  556. // get the item
  557. CItem* pItem = FindItem(item);
  558. if (pItem == NULL) return false;
  559. if (pItem->m_undefined) return false;
  560. // check
  561. if (pItem->m_type == IT_DOUBLE)
  562. {
  563. dValue = pItem->m_dValue;
  564. return true;
  565. }
  566. return false;
  567. }
  568. bool CPropertyGrid::GetItemValue(HITEM item, bool& bValue) const
  569. {
  570. // get the item
  571. CItem* pItem = FindItem(item);
  572. if (pItem == NULL) return false;
  573. if (pItem->m_undefined) return false;
  574. // check
  575. if (pItem->m_type == IT_BOOLEAN || pItem->m_type == IT_CHECK )
  576. {
  577. bValue = pItem->m_bValue;
  578. return true;
  579. }
  580. return false;
  581. }
  582. bool CPropertyGrid::GetItemValue(HITEM item, COleDateTime& dtValue) const
  583. {
  584. // get the item
  585. CItem* pItem = FindItem(item);
  586. if (pItem == NULL) return false;
  587. if (pItem->m_undefined) return false;
  588. // check
  589. if (pItem->m_type == IT_DATE || pItem->m_type == IT_DATETIME)
  590. {
  591. dtValue = pItem->m_dtValue;
  592. return true;
  593. }
  594. return false;
  595. }
  596. bool CPropertyGrid::GetItemValue(HITEM item, COLORREF& clrValue) const
  597. {
  598. // get the item
  599. CItem* pItem = FindItem(item);
  600. if (pItem == NULL) return false;
  601. if (pItem->m_undefined) return false;
  602. // check
  603. if (pItem->m_type == IT_COLOR)
  604. {
  605. clrValue = pItem->m_clrValue;
  606. return true;
  607. }
  608. return false;
  609. }
  610. bool CPropertyGrid::GetItemValue(HITEM item, LOGFONT& lfValue) const
  611. {
  612. // get the item
  613. CItem* pItem = FindItem(item);
  614. if (pItem == NULL) return false;
  615. if (pItem->m_undefined) return false;
  616. // check
  617. if (pItem->m_type == IT_FONT)
  618. {
  619. lfValue = pItem->m_lfValue;
  620. return true;
  621. }
  622. return false;
  623. }
  624. bool CPropertyGrid::SetItemValue(HITEM item, const string strValue)
  625. {
  626. // get the item
  627. CItem* pItem = FindItem(item);
  628. if (pItem == NULL) return false;
  629. // check
  630. if (pItem->m_type == IT_STRING || pItem->m_type == IT_TEXT || pItem->m_type == IT_FILE || pItem->m_type == IT_FOLDER)
  631. {
  632. pItem->m_strValue = strValue;
  633. pItem->m_undefined = false;
  634. Invalidate();
  635. return true;
  636. }
  637. return false;
  638. }
  639. bool CPropertyGrid::SetItemValue(HITEM item, const int nValue)
  640. {
  641. // get the item
  642. CItem* pItem = FindItem(item);
  643. if (pItem == NULL) return false;
  644. // check
  645. if (pItem->m_type == IT_COMBO || pItem->m_type == IT_INTEGER)
  646. {
  647. pItem->m_nValue = nValue;
  648. pItem->m_undefined = false;
  649. Invalidate();
  650. return true;
  651. }
  652. return false;
  653. }
  654. bool CPropertyGrid::SetItemValue(HITEM item, const double dValue)
  655. {
  656. // get the item
  657. CItem* pItem = FindItem(item);
  658. if (pItem == NULL) return false;
  659. // check
  660. if (pItem->m_type == IT_DOUBLE)
  661. {
  662. pItem->m_dValue = dValue;
  663. pItem->m_undefined = false;
  664. Invalidate();
  665. return true;
  666. }
  667. return false;
  668. }
  669. bool CPropertyGrid::SetItemValue(HITEM item, const bool bValue)
  670. {
  671. // get the item
  672. CItem* pItem = FindItem(item);
  673. if (pItem == NULL) return false;
  674. // check
  675. if (pItem->m_type == IT_BOOLEAN || pItem->m_type == IT_CHECK )
  676. {
  677. pItem->m_bValue = bValue;
  678. pItem->m_undefined = false;
  679. Invalidate();
  680. return true;
  681. }
  682. return false;
  683. }
  684. bool CPropertyGrid::SetItemValue(HITEM item, const COleDateTime dtValue)
  685. {
  686. // get the item
  687. CItem* pItem = FindItem(item);
  688. if (pItem == NULL) return false;
  689. // check
  690. if (pItem->m_type == IT_DATE || pItem->m_type == IT_DATETIME)
  691. {
  692. pItem->m_dtValue = dtValue;
  693. pItem->m_undefined = false;
  694. Invalidate();
  695. return true;
  696. }
  697. return false;
  698. }
  699. bool CPropertyGrid::SetItemValue(HITEM item, const COLORREF clrValue)
  700. {
  701. // get the item
  702. CItem* pItem = FindItem(item);
  703. if (pItem == NULL) return false;
  704. // check
  705. if (pItem->m_type == IT_COLOR)
  706. {
  707. pItem->m_clrValue = clrValue;
  708. pItem->m_undefined = false;
  709. Invalidate();
  710. return true;
  711. }
  712. return false;
  713. }
  714. bool CPropertyGrid::SetItemValue(HITEM item, const LOGFONT lfValue)
  715. {
  716. // get the item
  717. CItem* pItem = FindItem(item);
  718. if (pItem == NULL) return false;
  719. // check
  720. if (pItem->m_type == IT_FONT)
  721. {
  722. memcpy(&pItem->m_lfValue, &lfValue, sizeof(LOGFONT));
  723. pItem->m_undefined = false;
  724. Invalidate();
  725. return true;
  726. }
  727. return false;
  728. }
  729. int CPropertyGrid::GetTextMargin()
  730. {
  731. return 2*margin;
  732. }
  733. CFont* CPropertyGrid::GetFontNormal()
  734. {
  735. return &m_fntNormal;
  736. }
  737. CFont* CPropertyGrid::GetFontBold()
  738. {
  739. return &m_fntBold;
  740. }
  741. BEGIN_MESSAGE_MAP(CPropertyGrid, CWnd)
  742. ON_WM_PAINT()
  743. ON_WM_LBUTTONDOWN()
  744. ON_WM_MOUSEMOVE()
  745. ON_WM_CREATE()
  746. ON_WM_LBUTTONUP()
  747. ON_WM_VSCROLL()
  748. ON_WM_ERASEBKGND()
  749. ON_MESSAGE(WM_PG_COMBOSELCHANGED, OnComboSelChanged)
  750. ON_MESSAGE(WM_PG_ENDLABELEDIT, OnEditChanged)
  751. ON_MESSAGE(WM_PG_DATESELCHANGED, OnDateChanged)
  752. ON_WM_LBUTTONDBLCLK()
  753. ON_WM_MOUSEWHEEL()
  754. ON_WM_DESTROY()
  755. ON_WM_SIZE()
  756. ON_WM_GETDLGCODE()
  757. ON_WM_CHAR()
  758. ON_WM_KEYDOWN()
  759. END_MESSAGE_MAP()
  760. //
  761. // creation and window stuff
  762. //
  763. void CPropertyGrid::InitControl()
  764. {
  765. // first gutter
  766. CRect rc;
  767. GetClientRect(&rc);
  768. m_gutter_width = rc.Width()/2;
  769. // check if already done
  770. if (m_fntNormal.GetSafeHandle() == NULL)
  771. {
  772. // fonts
  773. LOGFONT lf;
  774. if (GetParent() && GetParent()->GetFont())
  775. {
  776. CFont* pFont = GetParent()->GetFont();
  777. pFont->GetLogFont(&lf);
  778. m_fntNormal.CreateFontIndirect(&lf);
  779. lf.lfWeight = FW_BOLD;
  780. m_fntBold.CreateFontIndirect(&lf);
  781. }
  782. else
  783. {
  784. m_fntNormal.CreatePointFont(85, "Tahoma");
  785. m_fntNormal.GetLogFont(&lf);
  786. lf.lfWeight = FW_BOLD;
  787. m_fntBold.CreateFontIndirect(&lf);
  788. }
  789. }
  790. // get line height
  791. CDC* pDC = GetDC();
  792. CFont* pOldFont = pDC->SelectObject(&m_fntNormal);
  793. m_line_height = pDC->GetTextExtent("Gg").cy + 2*margin;
  794. pDC->SelectObject(pOldFont);
  795. ReleaseDC(pDC);
  796. // styles
  797. ModifyStyle(0, WS_CLIPCHILDREN);
  798. // try to get some strings
  799. if (m_strOk.empty())
  800. {
  801. m_strOk = "OK";
  802. if (GetParent() && GetParent()->GetDlgItem(IDOK))
  803. {
  804. CString strOk;
  805. GetParent()->GetDlgItem(IDOK)->GetWindowText(strOk);
  806. m_strOk = strOk;
  807. }
  808. }
  809. if (m_strCancel.empty())
  810. {
  811. m_strCancel = "Cancel";
  812. if (GetParent() && GetParent()->GetDlgItem(IDCANCEL))
  813. {
  814. CString strCancel;
  815. GetParent()->GetDlgItem(IDCANCEL)->GetWindowText(strCancel);
  816. m_strCancel = strCancel;
  817. }
  818. }
  819. }
  820. int CPropertyGrid::OnCreate(LPCREATESTRUCT lpCreateStruct)
  821. {
  822. if (CWnd::OnCreate(lpCreateStruct) == -1) return -1;
  823. InitControl();
  824. return 0;
  825. }
  826. void CPropertyGrid::PreSubclassWindow()
  827. {
  828. InitControl();
  829. CWnd::PreSubclassWindow();
  830. }
  831. void CPropertyGrid::OnDestroy()
  832. {
  833. DeleteEditControl();
  834. CWnd::OnDestroy();
  835. }
  836. void CPropertyGrid::OnSize(UINT nType, int cx, int cy)
  837. {
  838. CWnd::OnSize(nType, cx, cy);
  839. if (m_scrollbar.GetSafeHwnd())
  840. {
  841. CRect rect;
  842. GetClientRect(&rect);
  843. m_scrollbar.MoveWindow(rect.right - GetSystemMetrics(SM_CXVSCROLL), rect.top, GetSystemMetrics(SM_CXVSCROLL), rect.Height());
  844. RecalcLayout();
  845. }
  846. }
  847. //
  848. // painting
  849. //
  850. BOOL CPropertyGrid::OnEraseBkgnd(CDC* pDC)
  851. {
  852. return TRUE;
  853. }
  854. bool item_alpha_sort(vector<CPropertyGrid::CItem>::iterator it1, vector<CPropertyGrid::CItem>::iterator it2)
  855. {
  856. return (it1->m_name.compare(it2->m_name) < 0);
  857. }
  858. void CPropertyGrid::OnPaint()
  859. {
  860. // stuff needed
  861. const int sign_size = 8;
  862. // the scrollbar offset
  863. int top = GetScrollOffset();
  864. // the rect
  865. CRect rc_dummy;
  866. GetClientRect(&rc_dummy);
  867. if (m_scroll_enabled)
  868. rc_dummy.right -= GetSystemMetrics(SM_CXVSCROLL);
  869. // make sure we do not modify this one
  870. // because we use it to bitblt
  871. const CRect rc(rc_dummy);
  872. // stuff for flicker free drawing
  873. CDC dcMem;
  874. CBitmap bmpMem;
  875. CPaintDC dc(this);
  876. // create and configure the memdc
  877. dcMem.CreateCompatibleDC(&dc);
  878. bmpMem.CreateCompatibleBitmap(&dc, rc.Width(), rc.Height());
  879. CBitmap* pOldBmp = dcMem.SelectObject(&bmpMem);
  880. // brush needed
  881. CBrush brushTitle;
  882. brushTitle.CreateSolidBrush(m_clrTitle);
  883. // pen needed
  884. CPen penShade(PS_SOLID, 1, m_clrShade);
  885. CPen penTitle(PS_SOLID, 1, m_clrTitle);
  886. // to make sure we won't leak gdi resources
  887. CBrush* pOldBrush = dcMem.SelectObject(&brushTitle);
  888. CPen* pOldPen = dcMem.SelectObject(&penShade);
  889. CFont* pOldFont = dcMem.SelectObject(&m_fntNormal);
  890. // needed
  891. int w = rc.Width();
  892. // blank
  893. dcMem.FillSolidRect(rc, m_clrBack);
  894. dcMem.SetBkMode(TRANSPARENT);
  895. // empty text
  896. if (m_sections.empty())
  897. {
  898. CRect rect = rc;
  899. rect.top += 10;
  900. rect.DeflateRect(rect.Width()/4, 0);
  901. dcMem.DrawText(m_strEmpty.c_str(), rect, DT_CENTER|DT_WORDBREAK|DT_NOPREFIX);
  902. }
  903. else
  904. {
  905. // needed
  906. int sign_left = margin;
  907. // we start here
  908. int y = -top;
  909. // alphabetical needs special
  910. if (m_display_mode == DM_ALPHABETICAL)
  911. {
  912. // put all the items in a vector
  913. vector<vector<CItem>::iterator> lst;
  914. for (vector<CSection>::iterator it = m_sections.begin(); it != m_sections.end(); ++it)
  915. {
  916. for (vector<CItem>::iterator it2 = it->m_items.begin(); it2 != it->m_items.end(); ++it2)
  917. lst.push_back(it2);
  918. }
  919. // sort the vector
  920. sort(lst.begin(), lst.end(), item_alpha_sort);
  921. // display the items
  922. for (vector<vector<CItem>::iterator>::iterator it2 = lst.begin(); it2 != lst.end(); ++it2)
  923. {
  924. // first reset
  925. (*it2)->m_rcName.SetRectEmpty();
  926. (*it2)->m_rcValue.SetRectEmpty();
  927. // draw if visible
  928. (*it2)->m_rcName = CRect(0, y, w, y+m_line_height);
  929. CRect rcInter = (*it2)->m_rcName;
  930. rcInter.IntersectRect(rc, rcInter);
  931. if (!rcInter.IsRectEmpty())
  932. DrawItem(dcMem, w, sign_left+sign_size, y, *it2);
  933. // next line
  934. y += m_line_height;
  935. }
  936. }
  937. else
  938. {
  939. // next iterate on sections
  940. for (vector<CSection>::iterator it = m_sections.begin(); it != m_sections.end(); ++it)
  941. {
  942. // reset
  943. it->m_rcSign.SetRectEmpty();
  944. it->m_rcTitle.SetRectEmpty();
  945. // is visible?
  946. it->m_rcTitle = CRect(0, y, w, y+m_line_height);
  947. CRect rcInter = it->m_rcTitle;
  948. rcInter.IntersectRect(rcInter, rc);
  949. if (m_display_mode == DM_CATEGORIZED && !rcInter.IsRectEmpty())
  950. {
  951. // first shade rect
  952. if (m_shade_titles)
  953. dcMem.FillSolidRect(0, y, w, m_line_height, m_clrShade);
  954. // now draw a separator lines
  955. if (m_draw_lines)
  956. {
  957. dcMem.SelectObject(&penShade);
  958. dcMem.MoveTo(0, y);
  959. dcMem.LineTo(w+1, y);
  960. dcMem.MoveTo(0, y+m_line_height);
  961. dcMem.LineTo(w+1, y+m_line_height);
  962. }
  963. // now draw gutter
  964. if (m_draw_gutter)
  965. {
  966. dcMem.SelectObject(&penShade);
  967. dcMem.MoveTo(m_gutter_width, y);
  968. dcMem.LineTo(m_gutter_width, y+m_line_height+1);
  969. }
  970. // now draw collapse sign
  971. int sign_top = y+margin+2;
  972. dcMem.SelectObject(&penTitle);
  973. it->m_rcSign = CRect(sign_left, sign_top, sign_left+sign_size+1, sign_top+sign_size+1);
  974. dcMem.FrameRect(it->m_rcSign, &brushTitle);
  975. dcMem.MoveTo(sign_left+2, sign_top+sign_size/2);
  976. dcMem.LineTo(sign_left+2+sign_size/2+1, sign_top+sign_size/2);
  977. if (it->m_collapsed)
  978. {
  979. dcMem.MoveTo(sign_left+sign_size/2, sign_top+2);
  980. dcMem.LineTo(sign_left+sign_size/2, sign_top+2+sign_size/2+1);
  981. }
  982. // prepare draw text
  983. int title_left = sign_left+sign_size+2*margin;
  984. int title_top = y;
  985. dcMem.SelectObject(&m_fntBold);
  986. it->m_rcTitle = CRect(title_left, title_top, w, title_top+m_line_height);
  987. // draw focus rect
  988. if (m_focused_section == it->m_id)
  989. {
  990. CSize sz = dcMem.GetTextExtent(it->m_title.c_str());
  991. int rect_left = title_left;
  992. int rect_top = title_top+(m_line_height-sz.cy)/2;
  993. int rect_width = sz.cx+3*margin;
  994. int rect_height = sz.cy;
  995. dcMem.DrawFocusRect(CRect(rect_left, rect_top, rect_left+rect_width, rect_top+rect_height));
  996. }
  997. // now draw text
  998. dcMem.SetTextColor(m_clrTitle);
  999. dcMem.DrawText(it->m_title.c_str(), CRect(title_left+GetTextMargin(), title_top, w, title_top+m_line_height), DT_END_ELLIPSIS|DT_LEFT|DT_SINGLELINE|DT_VCENTER|DT_NOPREFIX);
  1000. }
  1001. // next line
  1002. if (m_display_mode == DM_CATEGORIZED)
  1003. y+=m_line_height;
  1004. // iterate on items
  1005. if (!it->m_collapsed || m_display_mode != DM_CATEGORIZED)
  1006. {
  1007. for (vector<CItem>::iterator it2 = it->m_items.begin(); it2 != it->m_items.end(); ++it2)
  1008. {
  1009. // reset
  1010. it2->m_rcName.SetRectEmpty();
  1011. it2->m_rcValue.SetRectEmpty();
  1012. // is visible?
  1013. it2->m_rcName = CRect(0, y, w, y+m_line_height);
  1014. CRect rcInter = it2->m_rcName;
  1015. rcInter.IntersectRect(rc, rcInter);
  1016. if (!rcInter.IsRectEmpty())
  1017. DrawItem(dcMem, w, sign_left+sign_size, y, it2);
  1018. // next line
  1019. y+=m_line_height;
  1020. }
  1021. }
  1022. }
  1023. }
  1024. }
  1025. // Blt the changes to the screen DC.
  1026. dc.BitBlt(rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, &dcMem, 0, 0, SRCCOPY);
  1027. // Done with off-screen bitmap and DC.
  1028. dcMem.SelectObject(pOldBmp);
  1029. dcMem.SelectObject(pOldFont);
  1030. dcMem.SelectObject(pOldPen);
  1031. dcMem.SelectObject(pOldBrush);
  1032. bmpMem.DeleteObject();
  1033. dcMem.DeleteDC();
  1034. // Validate All
  1035. ValidateRgn(NULL);
  1036. ValidateRect(NULL);
  1037. }
  1038. void CPropertyGrid::DrawItem(CDC& dc, int w, int x, int y, vector<CItem>::iterator& it)
  1039. {
  1040. // brush needed
  1041. CBrush brushText;
  1042. brushText.CreateSolidBrush(m_clrText);
  1043. // pen needed
  1044. CPen penShade(PS_SOLID, 1, m_clrShade);
  1045. // to make sure we won't leak gdi resources
  1046. CBrush* pOldBrush = dc.SelectObject(&brushText);
  1047. CPen* pOldPen = dc.SelectObject(&penShade);
  1048. CFont* pOldFont = dc.SelectObject(&m_fntNormal);
  1049. // first shade rect
  1050. if (m_shade_titles)
  1051. dc.FillSolidRect(0, y, x+2*margin, m_line_height, m_clrShade);
  1052. // now draw a separator line
  1053. if (m_draw_lines)
  1054. {
  1055. dc.SelectObject(&penShade);
  1056. dc.MoveTo(0, y+m_line_height);
  1057. dc.LineTo(w+1, y+m_line_height);
  1058. }
  1059. // now draw gutter
  1060. if (m_draw_gutter)
  1061. {
  1062. dc.SelectObject(&penShade);
  1063. dc.MoveTo(m_gutter_width, y);
  1064. dc.LineTo(m_gutter_width, y+m_line_height+1);
  1065. }
  1066. // needed
  1067. int name_left = x+2*margin+GetTextMargin();
  1068. int name_right = m_gutter_width-1;
  1069. int value_left = m_gutter_width;
  1070. int value_right = w;
  1071. // is being edited?
  1072. if (m_focused_item == it->m_id && it->m_editable && GetEditMode(*it) != EM_CUSTOM)
  1073. {
  1074. value_right -= m_line_height;
  1075. // the rect of the button
  1076. m_rect_button = CRect(w-m_line_height, y, w, y+m_line_height);
  1077. UINT pushed = m_button_depressed?DFCS_PUSHED:0;
  1078. // now draw the button
  1079. switch (GetEditMode(*it))
  1080. {
  1081. case EM_MODAL:
  1082. // draw a button
  1083. dc.DrawFrameControl(m_rect_button, DFC_BUTTON, DFCS_BUTTONPUSH|pushed);
  1084. dc.SelectObject(&m_fntBold);
  1085. dc.DrawText("...", m_rect_button, DT_CENTER|DT_SINGLELINE|DT_VCENTER|DT_NOPREFIX);
  1086. break;
  1087. case EM_DROPDOWN:
  1088. // draw an arrow
  1089. dc.DrawFrameControl(m_rect_button, DFC_SCROLL, DFCS_SCROLLDOWN|pushed);
  1090. break;
  1091. case EM_INPLACE:
  1092. // whole area is edit
  1093. m_rect_button.left = m_gutter_width;
  1094. break;
  1095. case EM_IMMEDIATE:
  1096. m_rect_button = AdjustCheckBoxRect(&CRect(value_left, y, value_right, y+m_line_height));
  1097. break;
  1098. default:
  1099. assert(false);
  1100. }
  1101. }
  1102. // update the rects
  1103. it->m_rcName = CRect(0, y, m_gutter_width, y+m_line_height);
  1104. it->m_rcValue = CRect(value_left, y, value_right, y+m_line_height);
  1105. CRect rcValue = it->m_rcValue;
  1106. rcValue.left += GetTextMargin();
  1107. // focused
  1108. if (m_focused_item == it->m_id)
  1109. {
  1110. int rect_left = name_left-2*margin;
  1111. int rect_right = name_right;
  1112. dc.FillSolidRect(rect_left, y, rect_right-rect_left+1, m_line_height, m_clrFocus);
  1113. dc.SetTextColor(m_clrHilite);
  1114. }
  1115. else
  1116. {
  1117. dc.SetTextColor(m_clrText);
  1118. }
  1119. // put name and value
  1120. dc.SelectObject(&m_fntNormal);
  1121. dc.DrawText(it->m_name.c_str(), -1, CRect(name_left, y, name_right, y+m_line_height), DT_END_ELLIPSIS|DT_LEFT|DT_SINGLELINE|DT_VCENTER|DT_NOPREFIX);
  1122. // get back to normal text
  1123. if (it->m_editable) dc.SetTextColor(m_clrEditable);
  1124. else dc.SetTextColor(m_clrDisabled);
  1125. // custom item
  1126. if (it->m_type == IT_CUSTOM)
  1127. {
  1128. int save = dc.SaveDC();
  1129. it->m_pCustom->DrawItem(dc, it->m_rcValue, m_focused_item == it->m_id);
  1130. dc.RestoreDC(save);
  1131. }
  1132. else
  1133. {
  1134. // modified flag
  1135. bool modified = (it->m_strValue != it->m_strValue_old);
  1136. // now draw text
  1137. string strValue = it->m_strValue;
  1138. switch (it->m_type)
  1139. {
  1140. case IT_TEXT:
  1141. {
  1142. size_t j;
  1143. for (;( j = strValue.find( "\r\n" )) != string::npos;)
  1144. strValue.replace( j, 2, "?");
  1145. break;
  1146. }
  1147. case IT_INTEGER:
  1148. {
  1149. CString strTemp;
  1150. string strFormat = "%d";
  1151. if (it->m_options.size() && !it->m_options.front().empty()) strFormat = it->m_options.front();
  1152. strTemp.Format(strFormat.c_str(), it->m_nValue);
  1153. strValue = LPCTSTR(strTemp);
  1154. modified = (it->m_nValue != it->m_nValue_old);
  1155. break;
  1156. }
  1157. case IT_DOUBLE:
  1158. {
  1159. CString strTemp;
  1160. string strFormat = "%g";
  1161. if (it->m_options.size() && !it->m_options.front().empty()) strFormat = it->m_options.front();
  1162. strTemp.Format(strFormat.c_str(), it->m_dValue);
  1163. strValue = LPCTSTR(strTemp);
  1164. modified = (it->m_dValue != it->m_dValue_old);
  1165. break;
  1166. }
  1167. case IT_DATE:
  1168. {
  1169. CString strTemp;
  1170. if (it->m_options.size() && !it->m_options.front().empty()) strTemp = it->m_dtValue.Format(it->m_options.front().c_str());
  1171. else strTemp = it->m_dtValue.Format(VAR_DATEVALUEONLY);
  1172. strValue = LPCTSTR(strTemp);
  1173. modified = (it->m_dtValue != it->m_dtValue_old);
  1174. break;
  1175. }
  1176. case IT_DATETIME:
  1177. {
  1178. CString strTemp;
  1179. if (it->m_options.size() && !it->m_options.front().empty()) strTemp = it->m_dtValue.Format(it->m_options.front().c_str());
  1180. else strTemp = it->m_dtValue.Format();
  1181. strValue = LPCTSTR(strTemp);
  1182. modified = (it->m_dtValue != it->m_dtValue_old);
  1183. break;
  1184. }
  1185. case IT_BOOLEAN:
  1186. {
  1187. strValue = it->m_bValue ? m_strTrue : m_strFalse;
  1188. modified = (it->m_bValue != it->m_bValue_old);
  1189. break;
  1190. }
  1191. case IT_COMBO:
  1192. {
  1193. if (it->m_nValue>=0 && it->m_nValue<int(it->m_options.size()))
  1194. strValue = it->m_options[it->m_nValue];
  1195. modified = (it->m_nValue != it->m_nValue_old);
  1196. break;
  1197. }
  1198. case IT_FILE:
  1199. case IT_FOLDER:
  1200. {
  1201. TCHAR szBuffer[1024];
  1202. strncpy(szBuffer, strValue.c_str(), 1024);
  1203. PathCompactPath(dc.GetSafeHdc(), szBuffer, rcValue.Width());
  1204. strValue = szBuffer;
  1205. break;
  1206. }
  1207. case IT_COLOR:
  1208. {
  1209. // draw a sample rectangle
  1210. CRect rc = rcValue;
  1211. rc.DeflateRect(0,2,0,2);
  1212. rc.top++;
  1213. rc.right = rc.left + m_line_height;
  1214. dc.FrameRect(rc, &brushText);
  1215. rc.DeflateRect(1,1);
  1216. dc.FillSolidRect(rc, it->m_clrValue);
  1217. rcValue.left = rc.right + 3*margin;
  1218. // update the text
  1219. CString strTemp;
  1220. strTemp.Format("%d; %d; %d", GetRValue(it->m_clrValue), GetGValue(it->m_clrValue), GetBValue(it->m_clrValue));
  1221. strValue = LPCTSTR(strTemp);
  1222. modified = (it->m_clrValue != it->m_clrValue_old);
  1223. break;
  1224. }
  1225. case IT_FONT:
  1226. {
  1227. CString strTemp;
  1228. strTemp.Format("%s; %dpt", it->m_lfValue.lfFaceName, -MulDiv(it->m_lfValue.lfHeight, 72, dc.GetDeviceCaps(LOGPIXELSY)));
  1229. strValue = LPCTSTR(strTemp);
  1230. modified = (memcmp(&it->m_lfValue, &it->m_lfValue_old, sizeof(LOGFONT))!=0);
  1231. break;
  1232. }
  1233. case IT_CHECK:
  1234. {
  1235. // draw a sample rectangle
  1236. CRect rc = AdjustCheckBoxRect(&(it->m_rcValue));
  1237. BITMAPINFO bmi;
  1238. bmi.bmiHeader.biBitCount = 32;
  1239. bmi.bmiHeader.biClrImportant = 0;
  1240. bmi.bmiHeader.biClrUsed = 0;
  1241. bmi.bmiHeader.biCompression = BI_RGB;
  1242. bmi.bmiHeader.biHeight = CheckBoxHeight;
  1243. bmi.bmiHeader.biPlanes = 1;
  1244. bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  1245. bmi.bmiHeader.biSizeImage = 0; //0 is ok for BI_RGB (uncompressed)
  1246. bmi.bmiHeader.biWidth = CheckBoxHeight;
  1247. bmi.bmiHeader.biXPelsPerMeter = 1;
  1248. bmi.bmiHeader.biYPelsPerMeter = 1;
  1249. void* pBuffer;
  1250. if ( it->m_editable )
  1251. pBuffer = it->m_bValue? &Item_CheckOn : &Item_CheckOff;
  1252. else
  1253. pBuffer = it->m_bValue? &Item_CheckOn_Disabled : &Item_CheckOff_Disabled;
  1254. StretchDIBits(dc.m_hDC, rc.left, rc.top, rc.Width(), rc.Height(), 0, CheckBoxHeight+1, CheckBoxHeight, -CheckBoxHeight, pBuffer, &bmi, DIB_RGB_COLORS, SRCCOPY);
  1255. break;
  1256. }
  1257. }
  1258. // we must also take undefined state change into account
  1259. modified |= (it->m_undefined != it->m_undefined_old);
  1260. // set proper font
  1261. if (modified && m_bold_modified) dc.SelectObject(&m_fntBold);
  1262. else if (it->m_editable && m_bold_editables) dc.SelectObject(&m_fntBold);
  1263. else dc.SelectObject(&m_fntNormal);
  1264. // now draw it
  1265. if (it->m_undefined) strValue = m_strUndefined;
  1266. dc.DrawText(strValue.c_str(), -1, rcValue, DT_END_ELLIPSIS|DT_LEFT|DT_SINGLELINE|DT_VCENTER|DT_NOPREFIX);
  1267. }
  1268. // clean up
  1269. dc.SelectObject(pOldFont);
  1270. dc.SelectObject(pOldPen);
  1271. dc.SelectObject(pOldBrush);
  1272. }
  1273. //
  1274. // mouse interaction
  1275. //
  1276. void CPropertyGrid::OnLButtonDown(UINT nFlags, CPoint point)
  1277. {
  1278. // destroy edit
  1279. SetFocus();
  1280. DeleteEditControl();
  1281. // click on button?
  1282. if (m_rect_button.PtInRect(point))
  1283. {
  1284. ASSERT(m_focused_item != -1);
  1285. CItem* pItem = FindItem(m_focused_item);
  1286. if ( pItem && pItem->m_type == IT_CHECK && pItem->m_editable)
  1287. {
  1288. pItem->m_bValue = !pItem->m_bValue;
  1289. GetOwner()->SendMessage(WM_PG_ITEMCHANGED, pItem->m_id);
  1290. }
  1291. else
  1292. {
  1293. m_button_pushed = true;
  1294. m_button_depressed = true;
  1295. SetCapture();
  1296. }
  1297. Invalidate();
  1298. return;
  1299. }
  1300. // click on button?
  1301. if (m_focused_item != -1)
  1302. {
  1303. CItem* pItem = FindItem(m_focused_item);
  1304. if ( pItem && pItem->m_type == IT_CUSTOM
  1305. && GetEditMode(*pItem) == EM_CUSTOM
  1306. && pItem->m_pCustom->OnLButtonDown(pItem->m_rcValue, point))
  1307. {
  1308. m_custom_tracking = true;
  1309. SetCapture();
  1310. Invalidate();
  1311. return;
  1312. }
  1313. }
  1314. // resizing gutter?
  1315. if (abs(point.x-m_gutter_width)<3)
  1316. {
  1317. ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
  1318. m_resizing_gutter = true;
  1319. m_ptLast = point;
  1320. SetCapture();
  1321. Invalidate();
  1322. return;
  1323. }
  1324. // disable focus
  1325. m_focused_item = -1;
  1326. m_focused_section = -1;
  1327. m_rect_button.SetRectEmpty();
  1328. // did we click on a section
  1329. if (m_display_mode == DM_CATEGORIZED)
  1330. {
  1331. for (vector<CSection>::iterator it = m_sections.begin(); it != m_sections.end(); ++it)
  1332. {
  1333. if (it->m_rcSign.PtInRect(point))
  1334. {
  1335. it->m_collapsed = !it->m_collapsed;
  1336. m_focused_section = it->m_id;
  1337. RecalcLayout();
  1338. return;
  1339. }
  1340. else if (it->m_rcTitle.PtInRect(point))
  1341. {
  1342. m_focused_section = it->m_id;
  1343. Invalidate();
  1344. return;
  1345. }
  1346. }
  1347. }
  1348. // focus
  1349. for (vector<CSection>::iterator it = m_sections.begin(); it != m_sections.end(); ++it)
  1350. {
  1351. if (!it->m_collapsed || m_display_mode != DM_CATEGORIZED)
  1352. {
  1353. for (vector<CItem>::iterator it2 = it->m_items.begin(); it2 != it->m_items.end(); ++it2)
  1354. {
  1355. if (it2->m_rcName.PtInRect(point) || it2->m_rcValue.PtInRect(point))
  1356. {
  1357. if (it2->m_editable || m_focus_disabled)
  1358. {
  1359. m_focused_item = it2->m_id;
  1360. if (it2->m_rcValue.PtInRect(point))
  1361. {
  1362. m_value_clicked = (GetEditMode(*it2) == EM_INPLACE || GetEditMode(*it2) == EM_DROPDOWN);
  1363. if ( it2->m_type == IT_CHECK && it2->m_editable)
  1364. {
  1365. CRect rc = AdjustCheckBoxRect(&(it2->m_rcValue));
  1366. if ( rc.PtInRect(point))
  1367. {
  1368. it2->m_bValue = !it2->m_bValue;
  1369. GetOwner()->SendMessage(WM_PG_ITEMCHANGED, it2->m_id);
  1370. }
  1371. }
  1372. }
  1373. Invalidate();
  1374. return;
  1375. }
  1376. }
  1377. }
  1378. }
  1379. }
  1380. CWnd::OnLButtonDown(nFlags, point);
  1381. Invalidate();
  1382. }
  1383. void CPropertyGrid::OnLButtonDblClk(UINT nFlags, CPoint point)
  1384. {
  1385. if (m_focused_item != -1)
  1386. {
  1387. CItem* pItem = FindItem(m_focused_item);
  1388. if (pItem)
  1389. {
  1390. if (pItem->m_type == IT_BOOLEAN)
  1391. {
  1392. if (!pItem->m_undefined)
  1393. {
  1394. pItem->m_bValue = !pItem->m_bValue;
  1395. GetOwner()->SendMessage(WM_PG_ITEMCHANGED, pItem->m_id);
  1396. Invalidate();
  1397. }
  1398. }
  1399. else if (pItem->m_type == IT_COMBO)
  1400. {
  1401. if (!pItem->m_undefined)
  1402. {
  1403. pItem->m_nValue = (pItem->m_nValue+1)%int(pItem->m_options.size());
  1404. GetOwner()->SendMessage(WM_PG_ITEMCHANGED, pItem->m_id);
  1405. Invalidate();
  1406. }
  1407. }
  1408. else if (GetEditMode(*pItem) == EM_MODAL)
  1409. {
  1410. EditFocusedItem();
  1411. }
  1412. }
  1413. }
  1414. else if (m_focused_section != -1)
  1415. {
  1416. CSection* pSection = FindSection(m_focused_section);
  1417. if (pSection)
  1418. {
  1419. pSection->m_collapsed = !pSection->m_collapsed;
  1420. Invalidate();
  1421. }
  1422. }
  1423. CWnd::OnLButtonDblClk(nFlags, point);
  1424. }
  1425. void CPropertyGrid::OnMouseMove(UINT nHitTest, CPoint point)
  1426. {
  1427. if (m_custom_tracking)
  1428. {
  1429. CItem* pItem = FindItem(m_focused_item);
  1430. if (pItem)
  1431. {
  1432. pItem->m_pCustom->OnMouseMove(pItem->m_rcValue, point);
  1433. Invalidate();
  1434. }
  1435. }
  1436. else if (m_button_pushed)
  1437. {
  1438. m_button_depressed = m_rect_button.PtInRect(point)?true:false;
  1439. Invalidate();
  1440. }
  1441. else if (m_resizing_gutter)
  1442. {
  1443. ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
  1444. m_gutter_width += point.x-m_ptLast.x;
  1445. CRect rc;
  1446. GetClientRect(&rc);
  1447. if (m_gutter_width<rc.Width()/5) m_gutter_width = rc.Width()/5;
  1448. if (m_gutter_width>4*rc.Width()/5) m_gutter_width = 4*rc.Width()/5;
  1449. m_ptLast = point;
  1450. Invalidate();
  1451. }
  1452. else if (!m_control)
  1453. {
  1454. if (abs(point.x-m_gutter_width)<3) ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
  1455. else ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
  1456. }
  1457. CWnd::OnMouseMove(nHitTest, point);
  1458. }
  1459. void CPropertyGrid::OnLButtonUp(UINT nFlags, CPoint point)
  1460. {
  1461. if (m_custom_tracking)
  1462. {
  1463. m_custom_tracking = false;
  1464. ReleaseCapture();
  1465. Invalidate();
  1466. CItem* pItem = FindItem(m_focused_item);
  1467. if (pItem)
  1468. pItem->m_pCustom->OnLButtonUp(pItem->m_rcValue, point);
  1469. }
  1470. else if (m_button_pushed || m_value_clicked)
  1471. {
  1472. m_button_pushed = false;
  1473. m_button_depressed = false;
  1474. ReleaseCapture();
  1475. Invalidate();
  1476. if (m_rect_button.PtInRect(point) || (m_value_clicked && m_focused_item != -1 && FindItem(m_focused_item) && FindItem(m_focused_item)->m_rcValue.PtInRect(point)))
  1477. {
  1478. m_value_clicked = false;
  1479. CItem* pItem = FindItem(m_focused_item);
  1480. if (pItem)
  1481. {
  1482. if (GetEditMode(*pItem) == EM_DROPDOWN)
  1483. {
  1484. if (pItem->m_type == IT_CUSTOM)
  1485. {
  1486. CRect rc = m_rect_button;
  1487. rc.left = m_gutter_width;
  1488. pItem->m_pCustom->ShowDropDown(rc);
  1489. }
  1490. else if (pItem->m_type == IT_DATE)
  1491. {
  1492. // the calendar rect
  1493. CRect rc = m_rect_button;
  1494. rc.left = m_gutter_width;
  1495. rc.top += m_line_height;
  1496. rc.bottom = rc.top + 100;
  1497. ClientToScreen(&rc);
  1498. // create it
  1499. m_control = new CPropertyGridMonthCalCtrl;
  1500. CPropertyGridMonthCalCtrl* mc = (CPropertyGridMonthCalCtrl*) m_control;
  1501. mc->CreateEx(0, MONTHCAL_CLASS, NULL, WS_POPUP|WS_BORDER, rc, GetParent(), 0);
  1502. mc->SetCurSel(pItem->m_dtValue);
  1503. mc->SetOwner(this);
  1504. mc->SizeMinReq();
  1505. // now position it
  1506. CRect rc2;
  1507. mc->GetWindowRect(&rc2);
  1508. rc2.OffsetRect(rc.right-rc2.right, 0);
  1509. mc->SetWindowPos(NULL, rc2.left, rc2.top, 0, 0, SWP_NOZORDER|SWP_NOSIZE|SWP_SHOWWINDOW);
  1510. }
  1511. else
  1512. {
  1513. // the combo rect
  1514. CRect rc = m_rect_button;
  1515. rc.left = m_gutter_width;
  1516. rc.top += m_line_height;
  1517. rc.bottom = rc.top + 100;
  1518. // create it
  1519. m_control = new CPropertyGridCombo();
  1520. CPropertyGridCombo* pCombo = (CPropertyGridCombo*)m_control;
  1521. pCombo->Create(WS_CHILD, rc, this, 0);
  1522. pCombo->SetColors(m_clrBack, m_clrText, m_clrFocus, m_clrHilite);
  1523. pCombo->SetFont(&m_fntNormal);
  1524. if (pItem->m_type == IT_BOOLEAN)
  1525. {
  1526. pCombo->AddString(m_strTrue);
  1527. pCombo->AddString(m_strFalse);
  1528. if (!pItem->m_undefined)
  1529. pCombo->SetCurSel(pItem->m_bValue?0:1);
  1530. }
  1531. else
  1532. {
  1533. for (vector<string>::iterator it = pItem->m_options.begin(); it != pItem->m_options.end(); ++it)
  1534. pCombo->AddString(*it);
  1535. if (!pItem->m_undefined)
  1536. pCombo->SetCurSel(pItem->m_nValue);
  1537. }
  1538. pCombo->ShowWindow(SW_SHOW);
  1539. }
  1540. }
  1541. else if (GetEditMode(*pItem) == EM_INPLACE)
  1542. {
  1543. // the in-place edit rect
  1544. CRect rc = m_rect_button;
  1545. rc.left++;
  1546. rc.top += margin;
  1547. // the value
  1548. string strValue;
  1549. if (pItem->m_type == IT_STRING)
  1550. {
  1551. strValue = pItem->m_strValue;
  1552. }
  1553. else if (pItem->m_type == IT_INTEGER)
  1554. {
  1555. if (!pItem->m_undefined)
  1556. {
  1557. CString strTemp;
  1558. strTemp.Format("%d", pItem->m_nValue);
  1559. strValue = LPCTSTR(strTemp);
  1560. }
  1561. }
  1562. else if (pItem->m_type == IT_DOUBLE)
  1563. {
  1564. if (!pItem->m_undefined)
  1565. {
  1566. CString strTemp;
  1567. strTemp.Format("%g", pItem->m_dValue);
  1568. strValue = LPCTSTR(strTemp);
  1569. }
  1570. }
  1571. else if (pItem->m_type == IT_CUSTOM)
  1572. {
  1573. strValue = pItem->m_pCustom->GetStringForInPlaceEdit();
  1574. }
  1575. else
  1576. {
  1577. assert(false);
  1578. }
  1579. // create it
  1580. m_control = new CPropertyGridInPlaceEdit(this, rc, WS_CHILD, 1000, strValue);
  1581. CPropertyGridInPlaceEdit* pEdit = (CPropertyGridInPlaceEdit*)m_control;
  1582. pEdit->SetColors(m_clrBack, m_clrText);
  1583. pEdit->SetFont(&m_fntNormal);
  1584. pEdit->ShowWindow(SW_SHOW);
  1585. }
  1586. else if (GetEditMode(*pItem) == EM_MODAL)
  1587. {
  1588. EditFocusedItem();
  1589. }
  1590. else if (GetEditMode(*pItem) == EM_CUSTOM)
  1591. {
  1592. pItem->m_pCustom->OnLButtonUp(pItem->m_rcValue, point);
  1593. }
  1594. else if (GetEditMode(*pItem) == EM_IMMEDIATE)
  1595. {
  1596. }
  1597. else
  1598. {
  1599. assert(false);
  1600. }
  1601. }
  1602. }
  1603. }
  1604. else if (m_resizing_gutter)
  1605. {
  1606. ReleaseCapture();
  1607. m_resizing_gutter = false;
  1608. ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
  1609. }
  1610. CWnd::OnLButtonUp(nFlags, point);
  1611. }
  1612. //
  1613. // keyboard interaction
  1614. //
  1615. UINT CPropertyGrid::OnGetDlgCode()
  1616. {
  1617. return CWnd::OnGetDlgCode()|DLGC_WANTCHARS|DLGC_WANTARROWS;
  1618. }
  1619. void CPropertyGrid::MoveForward(HSECTION& focused_section, HITEM& focused_item)
  1620. {
  1621. for (int pass = 0; pass<2; pass++)
  1622. {
  1623. bool found = false;
  1624. bool stop_on_next_valid = false;
  1625. if (focused_section == -1 && focused_item == -1)
  1626. stop_on_next_valid = true;
  1627. for (vector<CSection>::iterator it = m_sections.begin(); it != m_sections.end(); ++it)
  1628. {
  1629. if (m_display_mode == DM_CATEGORIZED)
  1630. {
  1631. if (it->m_id == focused_section)
  1632. {
  1633. stop_on_next_valid = true;
  1634. }
  1635. else if (stop_on_next_valid)
  1636. {
  1637. focused_section = it->m_id;
  1638. focused_item = -1;
  1639. found = true;
  1640. break;
  1641. }
  1642. }
  1643. if (!it->m_collapsed || m_display_mode != DM_CATEGORIZED)
  1644. {
  1645. for (vector<CItem>::iterator it2 = it->m_items.begin(); it2 != it->m_items.end(); ++it2)
  1646. {
  1647. if (it2->m_id == focused_item)
  1648. {
  1649. stop_on_next_valid = true;
  1650. }
  1651. else if (stop_on_next_valid)
  1652. {
  1653. if (it2->m_editable || m_focus_disabled)
  1654. {
  1655. focused_section = -1;
  1656. focused_item = it2->m_id;
  1657. found = true;
  1658. break;
  1659. }
  1660. }
  1661. }
  1662. if (found)
  1663. break;
  1664. }
  1665. }
  1666. if (found)
  1667. break;
  1668. focused_section = -1;
  1669. focused_item = -1;
  1670. }
  1671. }
  1672. void CPropertyGrid::FocusNextItem()
  1673. {
  1674. // simple move forward
  1675. MoveForward(m_focused_section, m_focused_item);
  1676. // ensure visible
  1677. CRect rc(0,0,0,0);
  1678. if (m_focused_section != -1 && FindSection(m_focused_section)) rc = FindSection(m_focused_section)->m_rcTitle;
  1679. else if (m_focused_item != -1 && FindItem(m_focused_item)) rc = FindItem(m_focused_item)->m_rcName;
  1680. if (!rc.IsRectEmpty())
  1681. {
  1682. CRect rect;
  1683. GetClientRect(&rect);
  1684. rect.IntersectRect(rc, rect);
  1685. if (rect.Height() != m_line_height)
  1686. OnVScroll(SB_THUMBPOSITION, rc.top, &m_scrollbar);
  1687. }
  1688. // done
  1689. Invalidate();
  1690. }
  1691. void CPropertyGrid::FocusPrevItem()
  1692. {
  1693. for (vector<CSection>::iterator it = m_sections.begin(); it != m_sections.end(); ++it)
  1694. {
  1695. if (m_display_mode == DM_CATEGORIZED)
  1696. {
  1697. HSECTION focused_section = it->m_id;
  1698. HITEM focused_item = -1;
  1699. MoveForward(focused_section, focused_item);
  1700. if (focused_section == m_focused_section && focused_item == m_focused_item)
  1701. {
  1702. m_focused_section = it->m_id;
  1703. m_focused_item = -1;
  1704. break;
  1705. }
  1706. }
  1707. if (!it->m_collapsed || m_display_mode != DM_CATEGORIZED)
  1708. {
  1709. bool found = false;
  1710. for (vector<CItem>::iterator it2 = it->m_items.begin(); it2 != it->m_items.end(); ++it2)
  1711. {
  1712. if (!it2->m_editable && !m_focus_disabled)
  1713. continue;
  1714. HSECTION focused_section = -1;
  1715. HITEM focused_item = it2->m_id;
  1716. MoveForward(focused_section, focused_item);
  1717. if (focused_section == m_focused_section && focused_item == m_focused_item)
  1718. {
  1719. m_focused_section = -1;
  1720. m_focused_item = it2->m_id;
  1721. found = true;
  1722. break;
  1723. }
  1724. }
  1725. if (found)
  1726. break;
  1727. }
  1728. }
  1729. // ensure visible
  1730. CRect rc(0,0,0,0);
  1731. if (m_focused_section != -1 && FindSection(m_focused_section)) rc = FindSection(m_focused_section)->m_rcTitle;
  1732. else if (m_focused_item != -1 && FindItem(m_focused_item)) rc = FindItem(m_focused_item)->m_rcName;
  1733. if (!rc.IsRectEmpty())
  1734. {
  1735. CRect rect;
  1736. GetClientRect(&rect);
  1737. rect.IntersectRect(rc, rect);
  1738. if (rect.Height() != m_line_height)
  1739. OnVScroll(SB_THUMBPOSITION, rc.top, &m_scrollbar);
  1740. }
  1741. // done
  1742. Invalidate();
  1743. }
  1744. void CPropertyGrid::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
  1745. {
  1746. if (nChar == '*')
  1747. {
  1748. ExpandAll(true);
  1749. }
  1750. else if (nChar == '/')
  1751. {
  1752. ExpandAll(false);
  1753. }
  1754. else if (nChar == '+' || nChar == '-')
  1755. {
  1756. if (m_focused_section != -1)
  1757. {
  1758. CSection* pSection = FindSection(m_focused_section);
  1759. if (pSection) pSection->m_collapsed = (nChar=='-');
  1760. RecalcLayout();
  1761. }
  1762. }
  1763. CWnd::OnChar(nChar, nRepCnt, nFlags);
  1764. }
  1765. void CPropertyGrid::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  1766. {
  1767. if (nChar == VK_DOWN)
  1768. {
  1769. FocusNextItem();
  1770. }
  1771. else if (nChar == VK_UP)
  1772. {
  1773. FocusPrevItem();
  1774. }
  1775. else if (nChar == VK_LEFT)
  1776. {
  1777. if (m_focused_section != -1 && FindSection(m_focused_section) && FindSection(m_focused_section)->m_collapsed == false)
  1778. {
  1779. ExpandSection(m_focused_section, false);
  1780. }
  1781. else
  1782. {
  1783. FocusPrevItem();
  1784. }
  1785. }
  1786. else if (nChar == VK_RIGHT)
  1787. {
  1788. if (m_focused_section != -1 && FindSection(m_focused_section) && FindSection(m_focused_section)->m_collapsed == true)
  1789. {
  1790. ExpandSection(m_focused_section, true);
  1791. }
  1792. else
  1793. {
  1794. FocusNextItem();
  1795. }
  1796. }
  1797. CWnd::OnKeyDown(nChar, nRepCnt, nFlags);
  1798. }
  1799. //
  1800. // scrolling
  1801. //
  1802. void CPropertyGrid::RecalcLayout()
  1803. {
  1804. // save current scroll offset
  1805. int offset = GetScrollOffset();
  1806. // total height
  1807. int height = 0;
  1808. for (vector<CSection>::iterator it = m_sections.begin(); it != m_sections.end(); ++it)
  1809. {
  1810. if (m_display_mode == DM_CATEGORIZED)
  1811. height += m_line_height;
  1812. if (!it->m_collapsed || m_display_mode != DM_CATEGORIZED)
  1813. height += int(it->m_items.size())*m_line_height;
  1814. }
  1815. // client rect
  1816. CRect rc;
  1817. GetClientRect(&rc);
  1818. if (height < rc.Height())
  1819. {
  1820. if (m_scrollbar.GetSafeHwnd() != NULL)
  1821. {
  1822. m_scrollbar.EnableScrollBar(ESB_DISABLE_BOTH);
  1823. m_scrollbar.ShowScrollBar(FALSE);
  1824. }
  1825. m_scroll_enabled = false;
  1826. }
  1827. else
  1828. {
  1829. if (m_scrollbar.GetSafeHwnd() == NULL)
  1830. {
  1831. CRect rect = rc;
  1832. rect.left = rect.right - GetSystemMetrics(SM_CXVSCROLL);
  1833. m_scrollbar.Create(WS_CHILD|SBS_VERT, rect, this, 1000);
  1834. }
  1835. m_scrollbar.EnableScrollBar(ESB_ENABLE_BOTH);
  1836. SCROLLINFO info;
  1837. info.cbSize = sizeof(SCROLLINFO);
  1838. info.fMask = SIF_ALL;
  1839. info.nMin = 0;
  1840. info.nMax = height;
  1841. info.nPage = rc.Height();
  1842. info.nPos = min(offset, height);
  1843. info.nTrackPos = 2;
  1844. m_scrollbar.SetScrollInfo(&info);
  1845. m_scrollbar.ShowScrollBar();
  1846. m_scroll_enabled = true;
  1847. }
  1848. if (GetSafeHwnd())
  1849. Invalidate();
  1850. }
  1851. int CPropertyGrid::GetScrollOffset()
  1852. {
  1853. if (m_scrollbar && m_scrollbar.IsWindowEnabled() == TRUE)
  1854. return m_scrollbar.GetScrollPos();
  1855. return 0;
  1856. }
  1857. void CPropertyGrid::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  1858. {
  1859. // check
  1860. if (!m_scroll_enabled) return;
  1861. if (pScrollBar != &m_scrollbar) return;
  1862. if (nSBCode == SB_ENDSCROLL) return;
  1863. // set focus to us
  1864. SetFocus();
  1865. // get the scroll info
  1866. SCROLLINFO info;
  1867. info.cbSize = sizeof(SCROLLINFO);
  1868. info.fMask = SIF_ALL;
  1869. m_scrollbar.GetScrollInfo(&info);
  1870. int min = info.nMin;
  1871. int pos = info.nPos;
  1872. int max = info.nMax-info.nPage;
  1873. // the entire rect
  1874. CRect rect;
  1875. GetClientRect(&rect);
  1876. int h = rect.Height();
  1877. // the rect without the scrollbar
  1878. CRect rc(0,0,rect.right-GetSystemMetrics(SM_CXVSCROLL),rect.bottom);
  1879. switch(nSBCode)
  1880. {
  1881. case SB_TOP:
  1882. pScrollBar->SetScrollPos(min);
  1883. break;
  1884. case SB_BOTTOM:
  1885. pScrollBar->SetScrollPos(max);
  1886. break;
  1887. case SB_LINEDOWN:
  1888. if (pos+m_line_height>=max) pScrollBar->SetScrollPos(max);
  1889. else pScrollBar->SetScrollPos(pos+m_line_height);
  1890. break;
  1891. case SB_LINEUP:
  1892. if (pos-m_line_height<=min) pScrollBar->SetScrollPos(min);
  1893. else pScrollBar->SetScrollPos(pos-m_line_height);
  1894. break;
  1895. case SB_PAGEDOWN:
  1896. if (pos+h>=max) pScrollBar->SetScrollPos(max);
  1897. else pScrollBar->SetScrollPos(pos+h);
  1898. break;
  1899. case SB_PAGEUP:
  1900. if (pos-h<=min) pScrollBar->SetScrollPos(min);
  1901. else pScrollBar->SetScrollPos(pos-h);
  1902. break;
  1903. case SB_THUMBPOSITION:
  1904. case SB_THUMBTRACK:
  1905. int diff = nPos - pos;
  1906. if (diff == 0) return;
  1907. if (pos <= min && diff<0) return;
  1908. if (pos >= max && diff>0) return;
  1909. pScrollBar->SetScrollPos(nPos);
  1910. }
  1911. Invalidate();
  1912. CWnd::OnVScroll(nSBCode, nPos, pScrollBar);
  1913. }
  1914. BOOL CPropertyGrid::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
  1915. {
  1916. int steps = abs(zDelta)/WHEEL_DELTA;
  1917. for (int i=0; i<3*steps; i++)
  1918. {
  1919. if (zDelta>0) OnVScroll(SB_LINEUP, 0, &m_scrollbar);
  1920. if (zDelta<0) OnVScroll(SB_LINEDOWN, 0, &m_scrollbar);
  1921. }
  1922. return CWnd::OnMouseWheel(nFlags, zDelta, pt);
  1923. }
  1924. //
  1925. // editing
  1926. //
  1927. CPropertyGrid::EEditMode CPropertyGrid::GetEditMode(CItem& item)
  1928. {
  1929. switch (item.m_type)
  1930. {
  1931. case IT_CUSTOM:
  1932. return item.m_pCustom->GetEditMode();
  1933. case IT_STRING:
  1934. case IT_INTEGER:
  1935. case IT_DOUBLE:
  1936. return EM_INPLACE;
  1937. case IT_COMBO:
  1938. case IT_BOOLEAN:
  1939. case IT_DATE:
  1940. return EM_DROPDOWN;
  1941. case IT_TEXT:
  1942. case IT_DATETIME:
  1943. case IT_FILE:
  1944. case IT_FOLDER:
  1945. case IT_COLOR:
  1946. case IT_FONT:
  1947. return EM_MODAL;
  1948. case IT_CHECK:
  1949. return EM_IMMEDIATE;
  1950. default:
  1951. assert(false);
  1952. return EM_CUSTOM;
  1953. }
  1954. }
  1955. void CPropertyGrid::DeleteEditControl()
  1956. {
  1957. // destroy edit
  1958. if (m_control)
  1959. {
  1960. if (m_control->GetSafeHwnd())
  1961. m_control->DestroyWindow();
  1962. delete m_control;
  1963. m_control = NULL;
  1964. }
  1965. }
  1966. LRESULT CPropertyGrid::OnComboSelChanged(WPARAM wParam, LPARAM lParam)
  1967. {
  1968. CItem* pItem = FindItem(m_focused_item);
  1969. if (pItem)
  1970. {
  1971. if (pItem->m_type == IT_BOOLEAN)
  1972. {
  1973. pItem->m_bValue = (wParam == 0);
  1974. pItem->m_undefined = false;
  1975. GetOwner()->SendMessage(WM_PG_ITEMCHANGED, pItem->m_id);
  1976. DeleteEditControl();
  1977. Invalidate();
  1978. }
  1979. else if (pItem->m_type == IT_COMBO)
  1980. {
  1981. pItem->m_nValue = int(wParam);
  1982. pItem->m_undefined = false;
  1983. GetOwner()->SendMessage(WM_PG_ITEMCHANGED, pItem->m_id);
  1984. DeleteEditControl();
  1985. Invalidate();
  1986. }
  1987. else
  1988. {
  1989. assert(false);
  1990. }
  1991. }
  1992. return 0;
  1993. }
  1994. LRESULT CPropertyGrid::OnEditChanged(WPARAM wParam, LPARAM lParam)
  1995. {
  1996. CItem* pItem = FindItem(m_focused_item);
  1997. if (pItem)
  1998. {
  1999. if (pItem->m_type == IT_STRING)
  2000. {
  2001. pItem->m_strValue = string((char*)wParam);
  2002. pItem->m_undefined = false;
  2003. GetOwner()->SendMessage(WM_PG_ITEMCHANGED, pItem->m_id);
  2004. DeleteEditControl();
  2005. Invalidate();
  2006. }
  2007. else if (pItem->m_type == IT_INTEGER)
  2008. {
  2009. if (strlen((char*)wParam))
  2010. {
  2011. pItem->m_nValue = atoi((char*)wParam);
  2012. pItem->m_undefined = false;
  2013. GetOwner()->SendMessage(WM_PG_ITEMCHANGED, pItem->m_id);
  2014. }
  2015. DeleteEditControl();
  2016. Invalidate();
  2017. }
  2018. else if (pItem->m_type == IT_DOUBLE)
  2019. {
  2020. if (strlen((char*)wParam))
  2021. {
  2022. pItem->m_dValue = atof((char*)wParam);
  2023. pItem->m_undefined = false;
  2024. GetOwner()->SendMessage(WM_PG_ITEMCHANGED, pItem->m_id);
  2025. }
  2026. DeleteEditControl();
  2027. Invalidate();
  2028. }
  2029. else if (pItem->m_type == IT_CUSTOM)
  2030. {
  2031. if (pItem->m_pCustom->OnItemEdited(string((char*)wParam)))
  2032. GetOwner()->SendMessage(WM_PG_ITEMCHANGED, pItem->m_id);
  2033. DeleteEditControl();
  2034. Invalidate();
  2035. }
  2036. else
  2037. {
  2038. assert(false);
  2039. }
  2040. }
  2041. return 0;
  2042. }
  2043. LRESULT CPropertyGrid::OnDateChanged(WPARAM wParam, LPARAM lParam)
  2044. {
  2045. CItem* pItem = FindItem(m_focused_item);
  2046. if (pItem)
  2047. {
  2048. if (pItem->m_type == IT_DATE)
  2049. {
  2050. CPropertyGridMonthCalCtrl* mc = (CPropertyGridMonthCalCtrl*) m_control;
  2051. mc->GetCurSel(pItem->m_dtValue);
  2052. pItem->m_undefined = false;
  2053. GetOwner()->SendMessage(WM_PG_ITEMCHANGED, pItem->m_id);
  2054. DeleteEditControl();
  2055. Invalidate();
  2056. }
  2057. else
  2058. {
  2059. assert(false);
  2060. }
  2061. }
  2062. return 0;
  2063. }
  2064. void CPropertyGrid::EditFocusedItem()
  2065. {
  2066. CItem* pItem = FindItem(m_focused_item);
  2067. if (pItem)
  2068. {
  2069. if (!pItem->m_editable)
  2070. return;
  2071. if (pItem->m_type == IT_TEXT)
  2072. {
  2073. CDynDialogEx dlg(GetParent());
  2074. dlg.SetUseSystemButtons(FALSE);
  2075. dlg.SetWindowTitle(pItem->m_name.c_str());
  2076. dlg.SetFont(&m_fntNormal);
  2077. CString strValue = pItem->m_strValue.c_str();
  2078. dlg.AddDlgControl("EDIT", pItem->m_strValue.c_str(), STYLE_EDIT|WS_VSCROLL|WS_HSCROLL|ES_AUTOHSCROLL|ES_AUTOVSCROLL|ES_LEFT|ES_MULTILINE|ES_WANTRETURN, EXSTYLE_EDIT, CRect(7, 7, 200, 100), (void*) &strValue);
  2079. dlg.AddDlgControl("BUTTON", m_strOk.c_str(), STYLE_BUTTON, EXSTYLE_BUTTON, CRect(56, 106, 106, 120), NULL, IDOK);
  2080. dlg.AddDlgControl("BUTTON", m_strCancel.c_str(), STYLE_BUTTON, EXSTYLE_BUTTON, CRect(110, 106, 160, 120), NULL, IDCANCEL);
  2081. if (dlg.DoModal() == IDOK)
  2082. {
  2083. pItem->m_strValue = LPCTSTR(strValue);
  2084. pItem->m_undefined = false;
  2085. GetOwner()->SendMessage(WM_PG_ITEMCHANGED, pItem->m_id);
  2086. Invalidate();
  2087. }
  2088. }
  2089. else if (pItem->m_type == IT_DATETIME)
  2090. {
  2091. CDynDialogEx dlg(GetParent());
  2092. dlg.SetUseSystemButtons(FALSE);
  2093. dlg.SetWindowTitle(pItem->m_name.c_str());
  2094. dlg.SetFont(&m_fntNormal);
  2095. COleDateTime dtValueDate = pItem->m_dtValue;
  2096. CTime dtValueTime(pItem->m_dtValue.GetYear(), pItem->m_dtValue.GetMonth(), pItem->m_dtValue.GetDay(), pItem->m_dtValue.GetHour(), pItem->m_dtValue.GetMinute(), pItem->m_dtValue.GetSecond());
  2097. dlg.AddDlgControl("STATIC", m_strDate.c_str(), STYLE_STATIC, EXSTYLE_STATIC, CRect(7, 3, 60, 12));
  2098. dlg.AddDlgControl("STATIC", m_strTime.c_str(), STYLE_STATIC, EXSTYLE_STATIC, CRect(67, 3, 120, 12));
  2099. dlg.AddDlgControl("SysDateTimePick32", "", STYLE_DATETIMEPICKER|DTS_SHORTDATEFORMAT, EXSTYLE_DATETIMEPICKER, CRect(7, 13, 60, 26), (void*) &dtValueDate);
  2100. dlg.AddDlgControl("SysDateTimePick32", "", STYLE_DATETIMEPICKER|DTS_TIMEFORMAT , EXSTYLE_DATETIMEPICKER, CRect(67, 13, 120, 26), (void*) &dtValueTime);
  2101. dlg.AddDlgControl("BUTTON", m_strOk.c_str(), STYLE_BUTTON, EXSTYLE_BUTTON, CRect(7, 37, 60, 51), NULL, IDOK);
  2102. dlg.AddDlgControl("BUTTON", m_strCancel.c_str(), STYLE_BUTTON, EXSTYLE_BUTTON, CRect(67, 37, 120, 51), NULL, IDCANCEL);
  2103. if (dlg.DoModal() == IDOK)
  2104. {
  2105. pItem->m_dtValue.SetDateTime(dtValueDate.GetYear(), dtValueDate.GetMonth(), dtValueDate.GetDay(),
  2106. dtValueTime.GetHour(), dtValueTime.GetMinute(), dtValueTime.GetSecond());
  2107. pItem->m_undefined = false;
  2108. GetOwner()->SendMessage(WM_PG_ITEMCHANGED, pItem->m_id);
  2109. Invalidate();
  2110. }
  2111. }
  2112. else if (pItem->m_type == IT_COLOR)
  2113. {
  2114. CColorDialog dlg(pItem->m_clrValue, 0, GetParent());
  2115. if (dlg.DoModal() == IDOK)
  2116. {
  2117. pItem->m_clrValue = dlg.GetColor();
  2118. pItem->m_undefined = false;
  2119. GetOwner()->SendMessage(WM_PG_ITEMCHANGED, pItem->m_id);
  2120. Invalidate();
  2121. }
  2122. }
  2123. else if (pItem->m_type == IT_FILE)
  2124. {
  2125. CFileDialog dlg(TRUE, NULL, pItem->m_strValue.c_str(), OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, pItem->m_options.front().c_str(), GetParent());
  2126. if (dlg.DoModal() == IDOK)
  2127. {
  2128. pItem->m_strValue = dlg.GetPathName();
  2129. pItem->m_undefined = false;
  2130. GetOwner()->SendMessage(WM_PG_ITEMCHANGED, pItem->m_id);
  2131. Invalidate();
  2132. }
  2133. }
  2134. else if (pItem->m_type == IT_FOLDER)
  2135. {
  2136. CPropertyGridDirectoryPicker::m_strTitle = pItem->m_options.front();
  2137. if (CPropertyGridDirectoryPicker::PickDirectory(pItem->m_strValue, GetParent()->GetSafeHwnd()))
  2138. {
  2139. pItem->m_undefined = false;
  2140. GetOwner()->SendMessage(WM_PG_ITEMCHANGED, pItem->m_id);
  2141. Invalidate();
  2142. }
  2143. }
  2144. else if (pItem->m_type == IT_FONT)
  2145. {
  2146. CFontDialog dlg(&pItem->m_lfValue, CF_EFFECTS|CF_SCREENFONTS, NULL, GetParent());
  2147. if (dlg.DoModal() == IDOK)
  2148. {
  2149. memcpy(&pItem->m_lfValue, dlg.m_cf.lpLogFont, sizeof(LOGFONT));
  2150. pItem->m_undefined = false;
  2151. GetOwner()->SendMessage(WM_PG_ITEMCHANGED, pItem->m_id);
  2152. Invalidate();
  2153. }
  2154. }
  2155. else if (pItem->m_type == IT_CUSTOM)
  2156. {
  2157. if (pItem->m_pCustom->OnEditItem())
  2158. {
  2159. GetOwner()->SendMessage(WM_PG_ITEMCHANGED, pItem->m_id);
  2160. Invalidate();
  2161. }
  2162. }
  2163. else
  2164. {
  2165. assert(false);
  2166. }
  2167. }
  2168. }
  2169. HITEM CPropertyGrid::AddCheckItem(HSECTION section, string name, bool value, bool editable, bool undefined, HITEM after)
  2170. {
  2171. return AddItem(section, IT_CHECK, name, &value, editable, undefined, after);
  2172. }
  2173. CRect CPropertyGrid::AdjustCheckBoxRect(CRect* rc)
  2174. {
  2175. CRect rctmp = *rc;
  2176. rctmp.left += GetTextMargin();
  2177. rctmp.top++;
  2178. rctmp.top += ((rctmp.Height() - CheckBoxHeight) / 2);
  2179. rctmp.bottom = rctmp.top + CheckBoxHeight;
  2180. rctmp.right = rctmp.left + CheckBoxHeight; //m_line_height - 2;
  2181. return rctmp;
  2182. }