How to change the appearance of a Cell GroupOpener?
According to the documentation, CellGroupData
supports Dynamic
-object as its status. So with the help of CellGrouping -> Manual
, we can design our own "CellGroup opener". It can be a Button
or EventHandler
placed in CellDingbat
, CellFrameLabels
, etc. Here is a simple demostration (tested in Mathematica 9.0.1 and 10.0 pre-release on Windows 8.1):
openerIconOpen =
GraphicsBox[{RGBColor[0.26, 0.59, 0.26],
PolygonBox[{{0, -0.25`}, {-0.3`, 0.25`}, {0.3`, 0.25`}, {0, -0.25`}}]},
ImageSize -> 15, PlotRange -> All];
openerIconClosed =
GraphicsBox[{RGBColor[0.8, 0.16, 0.17],
PolygonBox[{{0.5, 0}, {0, -0.3}, {0, 0.3}, {0.5, 0}}]},
ImageSize -> 15, PlotRange -> All];
cellopenflag$1 = True;
cellopenflag$2 = False;
Clear[openerBoxFunc]
openerBoxFunc[flag_] := TagBox[
DynamicBox[If[flag, $CellContext`openerIconOpen, $CellContext`openerIconClosed]],
EventHandlerTag[{"MouseClicked" :> (flag = ! flag)}]
]
cellBodys = {
"This is a Text Cell.",
BoxData[RowBox[{"Another Text Cell with GridBox: ", GridBox[{{"a", "b", "c"}}, GridBoxDividers -> {"Rows" -> {{True}}, "Columns" -> {{True}}}]}]],
BoxData[RowBox[{"1", "-", "2"}]],
BoxData[RowBox[{"-", "1"}]],
BoxData[DynamicBox[GridBox[{{"cellopenflag$1", "cellopenflag$2"}, {cellopenflag$1, cellopenflag$2}}, GridBoxDividers -> {"Rows" -> {{True}}, "Columns" -> {{True}}}]]]
};
Notebook[{
(* Start of group 1: *)
Cell[CellGroupData[{
(* Cell 1: *)
Cell[cellBodys[[1]], "Text",
CellDingbat -> openerBoxFunc[$CellContext`cellopenflag$1]
],
(* Cell 2: *)
Cell[cellBodys[[2]], "Text"],
(* Start of group 2: *)
Cell[CellGroupData[{
(* Cell 3: *)
Cell[cellBodys[[3]], "Input",
CellDingbat -> openerBoxFunc[$CellContext`cellopenflag$2]
],
(* Cell 4: *)
Cell[cellBodys[[4]], "Output"]
},
Dynamic[$CellContext`cellopenflag$2]
]](* <- End of group 2. *)
},
Dynamic[$CellContext`cellopenflag$1]
]](* <- End of group 1. *),
(* Cell 5: *)
Cell[cellBodys[[5]], "Text"]
}(* <- End of Notebook body. *),
CellGrouping -> Manual,
ShowGroupOpener -> False
] // NotebookPut