From 4754ab1630290c29b97c37835d5e26155998e038 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Tue, 24 Jun 2008 12:48:01 +0000 Subject: [PATCH] Next part of tree state icon patches git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54343 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/treectrl/state1.xpm | 145 +++++++++++++++++++++++++++++++ samples/treectrl/state2.xpm | 144 +++++++++++++++++++++++++++++++ samples/treectrl/state3.xpm | 142 ++++++++++++++++++++++++++++++ samples/treectrl/state4.xpm | 145 +++++++++++++++++++++++++++++++ samples/treectrl/state5.xpm | 85 ++++++++++++++++++ samples/treectrl/treetest.cpp | 157 +++++++++++++++++++++++++++++++++- samples/treectrl/treetest.h | 22 ++++- src/common/treebase.cpp | 10 ++- src/generic/treectlg.cpp | 21 ++++- src/msw/treectrl.cpp | 37 ++++++++ 10 files changed, 899 insertions(+), 9 deletions(-) create mode 100644 samples/treectrl/state1.xpm create mode 100644 samples/treectrl/state2.xpm create mode 100644 samples/treectrl/state3.xpm create mode 100644 samples/treectrl/state4.xpm create mode 100644 samples/treectrl/state5.xpm diff --git a/samples/treectrl/state1.xpm b/samples/treectrl/state1.xpm new file mode 100644 index 0000000000..2568d711d1 --- /dev/null +++ b/samples/treectrl/state1.xpm @@ -0,0 +1,145 @@ +/* XPM */ +static char *state1_xpm[] = { +/* columns rows colors chars-per-pixel */ +"16 16 123 2", +"8. c #ADAF01", +"n c #E5E804", +"2. c #E5E806", +", c #FCFF00", +"R c #C4C601", +"J c #E5E809", +". c #FCFF05", +"*. c #D6D904", +"X c #FCFF13", +"6. c #A6A800", +"M c #EDF00E", +"$. c #A6A802", +" c #FFFFFF", +"H c #DEE104", +"0 c #F5F802", +"o c #FCFF22", +"s c #EEF101", +"t c #FAFC24", +"3. c #F3F506", +"_ c #FAFC27", +"f c #EEF106", +"} c #C8CB03", +"U c #FAFC32", +"' c #BEC000", +"/ c #EEF113", +"E c #BEC002", +"C c #FAFC36", +"l c #FAFC38", +"D c #D0D301", +"5. c #AFB100", +"e c #F6F90E", +"[ c #AFB102", +"@. c #A0A200", +"j c #F6F91C", +"G c #D8DB03", +"> c #FEFF86", +") c #F6F91F", +": c #FEFF8D", +"p c #FEFF8E", +"1. c #C9CC03", +"8 c #FEFF92", +"v c #E0E301", +".. c #EFF210", +"y c #FBFD35", +"4. c #F7FA02", +"P c #F4F61C", +"F c #D1D402", +"Z c #FBFD46", +"o. c #F7FA18", +"r c #F7FA19", +"! c #D9DC06", +"%. c #B8BA02", +"g c #F0F30C", +"4 c #FCFE2F", +"b c #E1E402", +"N c #F0F313", +" . c #E1E408", +"Y c #FCFE3A", +":. c #F8FB0A", +"B c #F5F71E", +"1 c #F8FB0B", +"5 c #FCFE43", +"m c #E9EC08", +"&. c #C8CA03", +"u c #FCFE4A", +"^ c #E9EC0C", +"0. c #DADD01", +"A c #FCFE54", +"z c #FCFE5D", +";. c #F1F40D", +"=. c #E2E507", +"~ c #E2E509", +"< c #F9FC05", +"= c #FDFF39", +"O c #FDFF3C", +"T c #FDFF3F", +"2 c #F9FC13", +"] c #A3A501", +"- c #FDFF50", +"3 c #F9FC1F", +"+. c #BABC00", +"L c #EFF114", +"+ c #FDFF56", +"q c #F2F504", +"S c #FDFF59", +"#. c #949601", +"6 c #FDFF5C", +"$ c #FDFF5F", +"9 c #FDFF61", +"@ c #FDFF63", +"# c #FDFF65", +"c c #FDFF67", +"a c #FDFF68", +"9. c #C2C402", +"{ c #BDC003", +"; c #FDFF6C", +"x c #FDFF70", +"7 c #FDFF76", +"i c #FDFF77", +"I c #F7F925", +"V c #F7F927", +"<. c #8D8F01", +"-. c #EBEE0A", +"K c #EBEE0C", +"7. c #A4A600", +"w. c #F3F600", +",. c #959700", +"h c #F3F612", +"X. c #F3F615", +"( c #F3F619", +"| c #D5D804", +"% c #FBFE0B", +"d c #ECEF03", +"O. c #FBFE13", +"k c #F8FA27", +"W c #C6C902", +"& c #FBFE18", +"` c #FBFE23", +"* c #FBFE24", +"w c #F4F709", +"Q c #CED103", +"q. c #EAEC01", +">. c #ADAF00", +/* pixels */ +" ", +" ", +" . X o O + @ # $ ", +" . % & * = - ; : > ; ", +" , < 1 2 3 4 5 6 7 8 > 9 ", +" 0 q w e r t y u $ i p a ", +" s d f g h j k l u z x c ", +" v b n m M N B V C Z A S ", +" D F G H J K L P I U Y T ", +" R E W Q ! ~ ^ / ( ) _ ` ", +" ' ] [ { } | .^ ..X.o.O. ", +" +.@.#.$.%.&.*.=.-.;.:.. ", +" >.,.<.] %.1.G 2.3.4. ", +" 5.6.7.8.9.0.q.w. ", +" ", +" " +}; diff --git a/samples/treectrl/state2.xpm b/samples/treectrl/state2.xpm new file mode 100644 index 0000000000..0eea6c30cd --- /dev/null +++ b/samples/treectrl/state2.xpm @@ -0,0 +1,144 @@ +/* XPM */ +static char *state2_xpm[] = { +/* columns rows colors chars-per-pixel */ +"16 16 122 2", +"4. c #54AF2C", +"9 c #95CF7C", +"K c #56A932", +"~ c #51A22E", +"Z c #82C665", +"0. c #4FA529", +"! c #4C9B2A", +"[ c #3C7C1F", +"' c #3F8620", +"x c #9FD488", +"6. c #37751C", +" c #FFFFFF", +"A c #8CCB71", +"# c #98D07F", +"5. c #3A7C1E", +"3 c #68B944", +"R c #428A22", +"X c #61B83B", +"| c #4A9827", +"*. c #4A9828", +"V c #6DBA4B", +"@ c #96D07D", +"> c #AEDA9A", +"s c #50A92A", +"/ c #5CAE38", +"3. c #55AD2F", +"} c #458E25", +"B c #66B643", +"& c #64B93F", +"v c #4B9F27", +".. c #5AAE36", +"$. c #38761E", +"0 c #53AD2B", +"X. c #5FB23B", +"c c #99D181", +"U c #75BF54", +"f c #53AA2E", +"= c #7AC35A", +"m c #53A72E", +"< c #56B12E", +"o. c #62B63E", +"% c #5BB534", +"7 c #A3D68D", +"N c #5DAF39", +"( c #62B33E", +"S c #90CD75", +"e c #5BB236", +") c #67B744", +"2 c #60B63A", +"b c #4CA028", +":. c #59B232", +"Q c #479326", +"7. c #37741C", +"w c #57AF31", +"G c #4A9A27", +"8. c #428923", +"_ c #6DBC4B", +"l c #79C159", +"T c #7EC55F", +"- c #8ACA6E", +"1 c #5AB333", +"@. c #35711B", +"H c #4D9E29", +"o c #6BBC47", +"` c #6BBC48", +": c #B3DDA0", +"p c #B3DDA1", +"y c #77C157", +"E c #408622", +"$ c #94CF7A", +"-. c #55A930", +"I c #6BB949", +"=. c #50A22C", +" . c #50A22D", +"q c #53AC2D", +"W c #438D23", +"5 c #81C663", +"<. c #306419", +"g c #58AD33", +"8 c #B6DEA4", +"q. c #51AC29", +"h c #5DB138", +"+. c #3E8320", +"9. c #499B26", +"L c #5DAE39", +"{ c #418722", +"&. c #448E24", +"+ c #8ECC72", +"j c #65B641", +"a c #9AD181", +". c #57B42F", +"F c #479525", +";. c #59AE34", +"Y c #7BC35B", +"n c #4FA32A", +"r c #63B63F", +"] c #37731C", +"i c #A4D68E", +"u c #85C868", +">. c #3A7A1E", +",. c #326919", +"k c #6DBB4B", +"#. c #32691A", +"J c #52A42E", +"1. c #458F25", +"t c #6BBB49", +"C c #77C057", +"O c #7CC45D", +"2. c #50A42C", +"^ c #55A831", +"P c #64B441", +"6 c #92CE77", +"z c #92CE78", +"D c #469324", +"M c #58AC34", +"4 c #73C052", +"%. c #3E8221", +"d c #51A82B", +", c #54B22B", +"O. c #60B73A", +"; c #9CD385", +"* c #6CBC49", +/* pixels */ +" ", +" ", +" . X o O + @ # $ ", +" . % & * = - ; : > ; ", +" , < 1 2 3 4 5 6 7 8 > 9 ", +" 0 q w e r t y u $ i p a ", +" s d f g h j k l u z x c ", +" v b n m M N B V C Z A S ", +" D F G H J K L P I U Y T ", +" R E W Q ! ~ ^ / ( ) _ ` ", +" ' ] [ { } | .^ ..X.o.O. ", +" +.@.#.$.%.&.*.=.-.;.:.. ", +" >.,.<.] %.1.G 2.3.4. ", +" 5.6.7.>.8.9.0.q. ", +" ", +" " +}; diff --git a/samples/treectrl/state3.xpm b/samples/treectrl/state3.xpm new file mode 100644 index 0000000000..ababed456d --- /dev/null +++ b/samples/treectrl/state3.xpm @@ -0,0 +1,142 @@ +/* XPM */ +static char *state3_xpm[] = { +/* columns rows colors chars-per-pixel */ +"16 16 120 2", +"7 c #E48D8D", +"> c #E79A9A", +"& c #D03F3F", +"=. c #C63434", +"F c #B02727", +",. c #A42525", +". c #CD2F2F", +"s c #C12A2A", +";. c #8C1E1E", +"5 c #D96363", +"-. c #CB3232", +" . c #C93B3B", +"0 c #C62B2B", +"$ c #DF7A7A", +"t c #D14949", +" c #FFFFFF", +"o. c #962020", +"&. c #B82C2C", +"p c #E8A1A1", +"P c #CF4949", +"2. c #C92C2C", +"f c #C22E2E", +"= c #D75A5A", +"^ c #C53838", +"e c #CA3636", +"d c #C02B2B", +"y c #D55757", +"X. c #CF3A3A", +"n c #BE2E2E", +"9. c #C52929", +"E c #A12323", +"#. c #952121", +"2 c #CD3A3A", +"z c #DE7878", +"R c #9A2222", +"A c #DE7575", +"3 c #D04444", +"M c #C63939", +"% c #CD3434", +"O. c #821B1B", +"X c #D03B3B", +"6. c #9D2323", +"9 c #DF7C7C", +"Y c #D95F5F", +"5. c #851C1C", +"$. c #A22424", +">. c #721919", +": c #E8A0A0", +"B c #CF4B4B", +"Q c #B12A2A", +"8. c #BD2929", +"w c #C73131", +"/ c #CA3E3E", +"<. c #BB2C2C", +"*. c #C03030", +"@ c #E07D7D", +"[ c #A32525", +"l c #D55959", +"8 c #E9A4A4", +"* c #D24949", +"W c #A82626", +"r c #CD3F3F", +"m c #C33434", +"{ c #AD2727", +"h c #C83838", +"O c #D85D5D", +"6 c #DE7777", +"] c #8E1F1F", +"a c #E18181", +"i c #E48E8E", +"T c #9F2222", +"@. c #871E1E", +"G c #B52929", +"1. c #C62F2F", +"o c #D34747", +"1 c #CB3333", +"~ c #BF3131", +"Z c #DC7171", +"S c #A92424", +"b c #BA2A2A", +"%. c #AE2828", +"- c #DC6E6E", +":. c #791919", +"x c #E28888", +"V c #D45757", +"N c #CC4343", +"} c #B82D2D", +"; c #E28585", +"I c #D45454", +"U c #D75B5B", +"u c #DA6868", +"7. c #B12626", +"K c #C53939", +"H c #BB2E2E", +"J c #C03232", +"+ c #DD7272", +"c c #B62727", +"D c #AA2525", +"| c #C53636", +"# c #E07F7F", +"g c #C53333", +"4. c #861C1C", +") c #D24B4B", +"( c #CD4444", +"! c #B92E2E", +"C c #D86565", +"_ c #D24848", +", c #CC2B2B", +"j c #CD4141", +"q c #C52D2D", +"4 c #D55252", +".. c #CD3E3E", +"' c #841C1C", +"k c #D04B4B", +"+. c #781A1A", +"< c #CA2E2E", +"L c #CB4141", +"` c #9A2020", +"3. c #8E1E1E", +"v c #B72828", +/* pixels */ +" ", +" ", +" . X o O + @ # $ ", +" . % & * = - ; : > ; ", +" , < 1 2 3 4 5 6 7 8 > 9 ", +" 0 q w e r t y u $ i p a ", +" s d f g h j k l u z x a ", +" c v b n m M N B V C Z A ", +" S D F G H J K L P I U Y ", +" T R E W Q ! ~ ^ / ( ) _ ", +" ` ' ] R [ { } ~ | ...X. ", +" o.O.+.@.#.$.%.&.*.=.-.. ", +" ;.:.>.' #.,.F <.1.2. ", +" 3.4.5.;.6.7.8.9. ", +" ", +" " +}; diff --git a/samples/treectrl/state4.xpm b/samples/treectrl/state4.xpm new file mode 100644 index 0000000000..341b44b958 --- /dev/null +++ b/samples/treectrl/state4.xpm @@ -0,0 +1,145 @@ +/* XPM */ +static char *state4_xpm[] = { +/* columns rows colors chars-per-pixel */ +"16 16 123 2", +"h c #3875C8", +"D c #245CA9", +"&. c #2459A2", +"#. c #1A4278", +"Z c #6596D8", +"w c #3171C7", +"v c #2763B6", +"=. c #2C67B8", +"| c #2760AD", +".. c #3672C5", +" c #FFFFFF", +"U c #548AD4", +"s c #2A6AC1", +"% c #3475CD", +";. c #3472C6", +"n c #2A67BA", +"6 c #77A3DE", +"3. c #2F6EC6", +"o. c #3E7ACD", +"F c #255DAA", +"} c #255AA3", +"` c #4882D2", +"1. c #255AA4", +"8 c #A4C1E9", +" . c #2D68B8", +"b c #2864B7", +"*. c #2861AE", +"# c #7FA8E0", +"P c #417BCB", +"V c #4B83CF", +"k c #4B83D0", +"8. c #1E4D8C", +"5. c #1E4D8E", +"= c #5A8FD7", +"T c #5F93D9", +"$. c #1E4A87", +"- c #6E9CDC", +"0. c #2661B1", +"r c #3F7BCD", +"3 c #447FD0", +"* c #4983D2", +"w. c #296BC5", +"q. c #2968BD", +"1 c #3373CB", +"f c #2E6CC2", +"/ c #3874C5", +"[ c #1F4E8E", +"^ c #316DBF", +"e c #3674CA", +"{ c #22559A", +"x c #88AEE2", +"7 c #8DB2E4", +"l c #598DD5", +"5 c #6395D9", +"p c #A1BFE8", +"9 c #7CA6DF", +"! c #2A63B1", +"a c #81AAE1", +"( c #3E79CA", +"B c #437DCC", +"+. c #205296", +"4 c #5289D5", +"> c #9ABBE7", +"q c #2D6DC5", +"K c #326EC0", +"9. c #23569D", +">. c #1E4C8C", +",. c #194279", +"<. c #193F72", +"0 c #2B6DC6", +"d c #2B6AC0", +"O. c #3A79CF", +"z c #78A3DE", +"@ c #7DA7E0", +"Q c #265DA8", +") c #447ECD", +"I c #4982CF", +"t c #4982D1", +"6. c #1C4986", +"m c #2E6BBE", +"H c #2964B5", +"~ c #2E68B9", +"o c #4782D3", +"; c #85ACE2", +"Y c #5B8FD7", +"4. c #2C6EC9", +"X c #3B7AD0", +"2. c #2C68BB", +"G c #2761B0", +"X. c #3B77C9", +"R c #22579F", +"E c #22549A", +". c #2F72CD", +"u c #6898DA", +"+ c #72A0DD", +"M c #3470C3", +"L c #3974C5", +"N c #3974C6", +"' c #20549A", +"c c #81A9E1", +"@. c #1B4782", +"C c #578CD4", +"y c #578CD5", +":. c #3273CB", +"S c #75A1DE", +"$ c #7AA5DF", +"j c #417CCD", +"W c #2358A1", +"_ c #4B84D2", +"i c #8EB2E4", +", c #2B6FCC", +"-. c #306DC0", +"2 c #3A78CD", +"& c #3F7CD0", +"%. c #215295", +"] c #1C4884", +"7. c #1C4885", +"O c #5D91D8", +": c #A0BFE8", +"< c #2E70CA", +"A c #719EDC", +"g c #3371C5", +"J c #2E6ABB", +/* pixels */ +" ", +" ", +" . X o O + @ # $ ", +" . % & * = - ; : > ; ", +" , < 1 2 3 4 5 6 7 8 > 9 ", +" 0 q w e r t y u $ i p a ", +" s d f g h j k l u z x c ", +" v b n m M N B V C Z A S ", +" D F G H J K L P I U Y T ", +" R E W Q ! ~ ^ / ( ) _ ` ", +" ' ] [ { } | .^ ..X.o.O. ", +" +.@.#.$.%.&.*.=.-.;.:.. ", +" >.,.<.] %.1.G 2.3.4. ", +" 5.6.7.8.9.0.q.w. ", +" ", +" " +}; diff --git a/samples/treectrl/state5.xpm b/samples/treectrl/state5.xpm new file mode 100644 index 0000000000..01e2722a0e --- /dev/null +++ b/samples/treectrl/state5.xpm @@ -0,0 +1,85 @@ +/* XPM */ +static char *state5_xpm[] = { +/* columns rows colors chars-per-pixel */ +"16 16 63 1", +", c Black", +"z c #1E1E1E", +"O c #3C3C3C", +"l c #080808", +"w c #353535", +" c #FFFFFF", +"u c #010101", +"C c #101010", +"< c #1F1F1F", +"9 c #090909", +"& c #181818", +"f c #272727", +"x c #363636", +"v c #545454", +"@ c #636363", +"7 c #020202", +"1 c #2F2F2F", +"3 c #5C5C5C", +"S c #0A0A0A", +"q c #191919", +"c c #464646", +"i c #030303", +"s c #121212", +"B c #3F3F3F", +"h c #5D5D5D", +"; c #6C6C6C", +"% c #0B0B0B", +"g c #383838", +"+ c #565656", +"# c #656565", +"5 c #929292", +"8 c #040404", +"X c #131313", +"o c #222222", +"a c #0C0C0C", +"= c #393939", +". c #050505", +"n c #141414", +"V c #232323", +"M c #323232", +"- c #505050", +"$ c #5F5F5F", +"D c #0D0D0D", +"d c #1C1C1C", +"N c #3A3A3A", +"k c #676767", +"4 c #767676", +"p c #060606", +"Z c #151515", +"* c #242424", +": c #8D8D8D", +"0 c #0E0E0E", +"e c #4A4A4A", +"b c #595959", +"y c #686868", +"r c #777777", +"> c #868686", +"A c #070707", +"m c #252525", +"2 c #434343", +"6 c #616161", +"j c #707070", +"t c #8E8E8E", +/* pixels */ +" ", +" ", +" .XoO+@#$ ", +" .%&*=-;:>; ", +" ,.%X<12345>6 ", +" 7890q*we$rty ", +" uipasdfgehjk ", +" u78l0Xzfxcvb ", +" u7i89andmMNB ", +" u77ip9aXqAppendCheckItem(TreeTest_ToggleSel, wxT("Toggle &selection mode\tCtrl-S")); #endif // NO_MULTIPLE_SELECTION style_menu->AppendCheckItem(TreeTest_ToggleImages, wxT("Toggle show ima&ges")); + style_menu->AppendCheckItem(TreeTest_ToggleStates, wxT("Toggle show st&ates")); style_menu->AppendCheckItem(TreeTest_ToggleAlternateImages, wxT("Toggle alternate images")); + style_menu->AppendCheckItem(TreeTest_ToggleAlternateStates, wxT("Toggle alternate state images")); style_menu->Append(TreeTest_SetImageSize, wxT("Set image si&ze...")); style_menu->AppendSeparator(); style_menu->Append(TreeTest_SetFgColour, wxT("Set &foreground colour...")); @@ -261,6 +274,7 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h) item_menu->Append(TreeTest_ClearBold, wxT("Make item ¬ bold")); item_menu->AppendSeparator(); item_menu->Append(TreeTest_ToggleIcon, wxT("Toggle the item's &icon")); + item_menu->Append(TreeTest_ToggleState, wxT("Toggle the item's &state")); item_menu->AppendSeparator(); item_menu->Append(TreeTest_ShowFirstVisible, wxT("Show &first visible")); #ifdef wxHAS_LAST_VISIBLE @@ -296,7 +310,9 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h) CreateTreeWithDefStyle(); menu_bar->Check(TreeTest_ToggleImages, true); + menu_bar->Check(TreeTest_ToggleStates, true); menu_bar->Check(TreeTest_ToggleAlternateImages, false); + menu_bar->Check(TreeTest_ToggleAlternateStates, false); #if wxUSE_STATUSBAR // create a status bar @@ -626,6 +642,20 @@ void MyFrame::OnToggleImages(wxCommandEvent& WXUNUSED(event)) } } +void MyFrame::OnToggleStates(wxCommandEvent& WXUNUSED(event)) +{ + if ( wxGetApp().ShowStates() ) + { + m_treeCtrl->CreateStateImageList(true); + wxGetApp().SetShowStates(false); + } + else + { + m_treeCtrl->CreateStateImageList(false); + wxGetApp().SetShowStates(true); + } +} + void MyFrame::OnToggleAlternateImages(wxCommandEvent& WXUNUSED(event)) { bool alternateImages = m_treeCtrl->AlternateImages(); @@ -634,6 +664,14 @@ void MyFrame::OnToggleAlternateImages(wxCommandEvent& WXUNUSED(event)) m_treeCtrl->CreateImageList(0); } +void MyFrame::OnToggleAlternateStates(wxCommandEvent& WXUNUSED(event)) +{ + bool alternateStates = m_treeCtrl->AlternateStates(); + + m_treeCtrl->SetAlternateStates(!alternateStates); + m_treeCtrl->CreateStateImageList(); +} + void MyFrame::OnToggleButtons(wxCommandEvent& WXUNUSED(event)) { #if USE_GENERIC_TREECTRL || !defined(__WXMSW__) @@ -715,6 +753,15 @@ void MyFrame::OnToggleIcon(wxCommandEvent& WXUNUSED(event)) m_treeCtrl->DoToggleIcon(item); } +void MyFrame::OnToggleState(wxCommandEvent& WXUNUSED(event)) +{ + wxTreeItemId item = m_treeCtrl->GetSelection(); + + CHECK_ITEM( item ); + + m_treeCtrl->DoToggleState(item); +} + void MyFrame::DoShowFirstOrLast(TreeFunc0_t pfn, const wxString& label) { const wxTreeItemId item = (m_treeCtrl->*pfn)(); @@ -772,11 +819,13 @@ MyTreeCtrl::MyTreeCtrl(wxWindow *parent, const wxWindowID id, const wxPoint& pos, const wxSize& size, long style) : wxTreeCtrl(parent, id, pos, size, style), - m_alternateImages(false) + m_alternateImages(false), + m_alternateStates(false) { m_reverseSort = false; CreateImageList(); + CreateStateImageList(); // Add some items to the tree AddTestItemsToTree(5, 2); @@ -836,6 +885,70 @@ void MyTreeCtrl::CreateImageList(int size) AssignImageList(images); } +void MyTreeCtrl::CreateStateImageList(bool del) +{ + if ( del ) + { + SetStateImageList(NULL); + return; + } + + wxImageList *states; + wxBusyCursor wait; + + if (m_alternateStates) + { + wxIcon icons[5]; + icons[0] = wxIcon(state1_xpm); // yellow + icons[1] = wxIcon(state2_xpm); // green + icons[2] = wxIcon(state3_xpm); // red + icons[3] = wxIcon(state4_xpm); // blue + icons[4] = wxIcon(state5_xpm); // black + + int width = icons[0].GetWidth(), + height = icons[0].GetHeight(); + + // Make an state image list containing small icons + states = new wxImageList(width, height, true); + + for ( size_t i = 0; i < WXSIZEOF(icons); i++ ) + states->Add(icons[i]); + } + else + { + int width = ::GetSystemMetrics(SM_CXMENUCHECK), + height = ::GetSystemMetrics(SM_CYMENUCHECK); + + // make an state checkbox image list + states = new wxImageList(width, height, true); + + wxBitmap checkBmp(width, height); + wxRect rect (0, 0, width, height); + + wxRendererNative& renderer = wxRendererNative::Get(); + + // create no checked image + { + // first create bitmap in a memory DC + wxMemoryDC memDC(checkBmp); + // then draw a check mark into it + renderer.DrawCheckBox(this, memDC, rect, 0); + } // select checkBmp out of memDC + + states->Add(checkBmp); + + // create checked image + { + wxMemoryDC memDC(checkBmp); + renderer.DrawCheckBox(this, memDC, rect, wxCONTROL_CHECKED); + } + + states->Add(checkBmp); + } + + AssignStateImageList(states); +} + #if USE_GENERIC_TREECTRL || !defined(__WXMSW__) void MyTreeCtrl::CreateButtonsImageList(int size) { @@ -936,6 +1049,9 @@ void MyTreeCtrl::AddItemsRecursively(const wxTreeItemId& idParent, wxTreeItemId id = AppendItem(idParent, str, image, imageSel, new MyTreeItemData(str)); + if ( wxGetApp().ShowStates() ) + SetItemState(id, 0); + // and now we also set the expanded one (only for the folders) if ( hasChildren && wxGetApp().ShowImages() ) { @@ -1018,6 +1134,28 @@ void MyTreeCtrl::DoToggleIcon(const wxTreeItemId& item) SetItemImage(item, image, wxTreeItemIcon_Selected); } +void MyTreeCtrl::DoToggleState(const wxTreeItemId& item) +{ + if ( m_alternateStates ) + { + // sets random state unlike current + int state = GetItemState(item); + int nState; + + srand (time(NULL)); + do { + nState = rand() % GetStateImageList()->GetImageCount(); + } while (nState == state); + + SetItemState(item, nState); + } + else + { + // we have only 2 checkbox states, so next state will be reversed + SetItemState(item, wxTREE_ITEMSTATE_NEXT); + } +} + void MyTreeCtrl::LogEvent(const wxChar *name, const wxTreeEvent& event) { wxTreeItemId item = event.GetItem(); @@ -1238,7 +1376,10 @@ void MyTreeCtrl::OnEndDrag(wxTreeEvent& event) // Finally, we only copy one item here but we might copy the entire tree if // we were dragging a folder. int image = wxGetApp().ShowImages() ? TreeCtrlIcon_File : -1; - AppendItem(itemDst, text, image); + wxTreeItemId id = AppendItem(itemDst, text, image); + + if ( wxGetApp().ShowStates() ) + SetItemState(id, GetItemState(itemSrc)); } void MyTreeCtrl::OnBeginLabelEdit(wxTreeEvent& event) @@ -1301,6 +1442,16 @@ void MyTreeCtrl::OnItemActivated(wxTreeEvent& event) wxLogMessage(wxT("OnItemActivated")); } +void MyTreeCtrl::OnItemStateClick(wxTreeEvent& event) +{ + // toggle item state + wxTreeItemId itemId = event.GetItem(); + DoToggleState(itemId); + + wxLogMessage(wxT("Item \"%s\" state changed to %d"), + GetItemText(itemId), GetItemState(itemId)); +} + void MyTreeCtrl::OnItemMenu(wxTreeEvent& event) { wxTreeItemId itemId = event.GetItem(); @@ -1309,7 +1460,7 @@ void MyTreeCtrl::OnItemMenu(wxTreeEvent& event) wxPoint clientpt = event.GetPoint(); wxPoint screenpt = ClientToScreen(clientpt); - wxLogMessage(wxT("OnItemMenu for item \"%s\" at screen coords (%i, %i)"), + wxLogMessage(wxT("OnItemMenu for item \"%s\" at screen coords (%i, %i)"), item ? item->GetDesc() : _T(""), screenpt.x, screenpt.y); ShowMenu(itemId, clientpt); diff --git a/samples/treectrl/treetest.h b/samples/treectrl/treetest.h index 2d6e989211..e2908c0c44 100644 --- a/samples/treectrl/treetest.h +++ b/samples/treectrl/treetest.h @@ -23,18 +23,21 @@ class MyApp : public wxApp { public: - MyApp() { m_showImages = true; m_showButtons = false; } + MyApp() { m_showImages = true; m_showStates = true; m_showButtons = false; } bool OnInit(); void SetShowImages(bool show) { m_showImages = show; } bool ShowImages() const { return m_showImages; } + void SetShowStates(bool show) { m_showStates = show; } + bool ShowStates() const { return m_showStates; } + void SetShowButtons(bool show) { m_showButtons = show; } bool ShowButtons() const { return m_showButtons; } private: - bool m_showImages, m_showButtons; + bool m_showImages, m_showStates, m_showButtons; }; class MyTreeItemData : public wxTreeItemData @@ -61,7 +64,7 @@ public: TreeCtrlIcon_FolderOpened }; - MyTreeCtrl() { m_alternateImages = false; } + MyTreeCtrl() { m_alternateImages = false; m_alternateStates = false; } MyTreeCtrl(wxWindow *parent, const wxWindowID id, const wxPoint& pos, const wxSize& size, long style); @@ -85,6 +88,7 @@ public: void OnSelChanging(wxTreeEvent& event); void OnTreeKeyDown(wxTreeEvent& event); void OnItemActivated(wxTreeEvent& event); + void OnItemStateClick(wxTreeEvent& event); void OnItemRClick(wxTreeEvent& event); void OnRMouseDown(wxMouseEvent& event); @@ -96,6 +100,7 @@ public: void CreateImageList(int size = 16); void CreateButtonsImageList(int size = 11); + void CreateStateImageList(bool del = false); void AddTestItemsToTree(size_t numChildren, size_t depth); @@ -104,6 +109,7 @@ public: void DoEnsureVisible() { if (m_lastItem.IsOk()) EnsureVisible(m_lastItem); } void DoToggleIcon(const wxTreeItemId& item); + void DoToggleState(const wxTreeItemId& item); void ShowMenu(wxTreeItemId id, const wxPoint& pt); @@ -114,6 +120,9 @@ public: void SetAlternateImages(bool show) { m_alternateImages = show; } bool AlternateImages() const { return m_alternateImages; } + void SetAlternateStates(bool show) { m_alternateStates = show; } + bool AlternateStates() const { return m_alternateStates; } + protected: virtual int OnCompareItems(const wxTreeItemId& i1, const wxTreeItemId& i2); @@ -137,6 +146,7 @@ private: wxTreeItemId m_lastItem, // for OnEnsureVisible() m_draggedItem; // item being dragged right now bool m_alternateImages; + bool m_alternateStates; // NB: due to an ugly wxMSW hack you _must_ use DECLARE_DYNAMIC_CLASS() // if you want your overloaded OnCompareItems() to be called. @@ -198,7 +208,9 @@ public: void OnRecreate(wxCommandEvent& event); void OnToggleButtons(wxCommandEvent& event); void OnToggleImages(wxCommandEvent& event); + void OnToggleStates(wxCommandEvent& event); void OnToggleAlternateImages(wxCommandEvent& event); + void OnToggleAlternateStates(wxCommandEvent& event); void OnSetImageSize(wxCommandEvent& event); void OnCollapseAndReset(wxCommandEvent& event); @@ -224,6 +236,7 @@ public: void OnDecSpacing(wxCommandEvent& event); void OnToggleIcon(wxCommandEvent& event); + void OnToggleState(wxCommandEvent& event); void OnShowFirstVisible(wxCommandEvent& WXUNUSED(event)) { DoShowFirstOrLast(&wxTreeCtrl::GetFirstVisibleItem, "first visible"); } @@ -301,7 +314,9 @@ enum TreeTest_DeleteAll, TreeTest_Recreate, TreeTest_ToggleImages, + TreeTest_ToggleStates, TreeTest_ToggleAlternateImages, + TreeTest_ToggleAlternateStates, TreeTest_ToggleButtons, TreeTest_SetImageSize, TreeTest_ToggleSel, @@ -314,6 +329,7 @@ enum TreeTest_IncSpacing, TreeTest_DecSpacing, TreeTest_ToggleIcon, + TreeTest_ToggleState, TreeTest_Select, TreeTest_Unselect, TreeTest_SelectRoot, diff --git a/src/common/treebase.cpp b/src/common/treebase.cpp index 548b01fb76..7a1a2d8fcf 100644 --- a/src/common/treebase.cpp +++ b/src/common/treebase.cpp @@ -110,13 +110,19 @@ void wxTreeCtrlBase::SetItemState(const wxTreeItemId& item, int state) { if ( state == wxTREE_ITEMSTATE_NEXT ) { - state = GetItemState(item) + 1; + int current = GetItemState(item); + if ( current == wxTREE_ITEMSTATE_NONE ) + return; + state = current + 1; if ( m_imageListState && state >= m_imageListState->GetImageCount() ) state = 0; } else if ( state == wxTREE_ITEMSTATE_PREV ) { - state = GetItemState(item) - 1; + int current = GetItemState(item); + if ( current == wxTREE_ITEMSTATE_NONE ) + return; + state = current - 1; if ( state == -1 ) state = m_imageListState ? m_imageListState->GetImageCount() - 1 : 0; } diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index 16735f2591..53c95a2aad 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -2106,6 +2106,20 @@ void wxGenericTreeCtrl::CalculateLineHeight() } } + if ( m_imageListState ) + { + // Calculate a m_lineHeight value from the state Image sizes. + // May be toggle off. Then wxGenericTreeCtrl will spread when + // necessary (which might look ugly). + int n = m_imageListState->GetImageCount(); + for (int i = 0; i < n ; i++) + { + int width = 0, height = 0; + m_imageListState->GetSize(i, width, height); + if (height > m_lineHeight) m_lineHeight = height; + } + } + if (m_imageListButtons) { // Calculate a m_lineHeight value from the Button image sizes. @@ -2143,6 +2157,11 @@ void wxGenericTreeCtrl::SetStateImageList(wxImageList *imageList) if (m_ownsImageListState) delete m_imageListState; m_imageListState = imageList; m_ownsImageListState = false; + m_dirty = true; + // Don't do any drawing if we're setting the list to NULL, + // since we may be in the process of deleting the tree control. + if (imageList) + CalculateLineHeight(); } void wxGenericTreeCtrl::SetButtonsImageList(wxImageList *imageList) @@ -2355,7 +2374,7 @@ void wxGenericTreeCtrl::PaintItem(wxGenericTreeItem *item, wxDC& dc) { dc.SetClippingRegion( item->GetX() + state_w, item->GetY(), image_w, total_h ); m_imageListNormal->Draw( image, dc, - item->GetX(), + item->GetX() + state_w, item->GetY() + ((total_h > image_h)?((total_h-image_h)/2):0), wxIMAGELIST_DRAW_TRANSPARENT ); dc.DestroyClippingRegion(); diff --git a/src/msw/treectrl.cpp b/src/msw/treectrl.cpp index 14246836db..46a215d3ba 100644 --- a/src/msw/treectrl.cpp +++ b/src/msw/treectrl.cpp @@ -2691,6 +2691,43 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) // notify us before painting each item *result = m_hasAnyAttr ? CDRF_NOTIFYITEMDRAW : CDRF_DODEFAULT; + + // windows in TreeCtrl use one-based index for item state images, + // 0 indexed image is not being used, we're using zero-based index, + // so we have to add temp image (of zero index) to state image list + // before we draw any item, then after items are drawn we have to + // delete it (in POSTPAINT notify) + if (m_imageListState && m_imageListState->GetImageCount() > 0) + { + #define hImageList (HIMAGELIST)m_imageListState->GetHIMAGELIST() + + // add temporary image + int width, height; + m_imageListState->GetSize(0, width, height); + + HBITMAP hbmpTemp = ::CreateBitmap(width, height, 1, 1, NULL); + int index = ::ImageList_Add(hImageList, hbmpTemp, hbmpTemp); + ::DeleteObject(hbmpTemp); + + if ( index != -1 ) + { + // move images to right + for ( int i = index; i > 0; i-- ) + ::ImageList_Copy(hImageList, i, hImageList, i-1, 0); + + // we must remove the image in POSTPAINT notify + *result |= CDRF_NOTIFYPOSTPAINT; + } + + #undef hImageList + } + break; + + case CDDS_POSTPAINT: + // we are deleting temp image of 0 index, which was + // added before items were drawn (in PREPAINT notify) + if (m_imageListState && m_imageListState->GetImageCount() > 0) + m_imageListState->Remove(0); break; case CDDS_ITEMPREPAINT: -- 2.45.2