1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright (C) 1998 The LyX Team.
8 *======================================================*/
13 #pragma implementation
16 #include "insetcollapsable.h"
19 #include "BufferView.h"
23 InsetCollapsable::InsetCollapsable(Buffer * bf): InsetText(bf)
29 framecolor = LColor::footnoteframe;
34 Inset * InsetCollapsable::Clone()
36 Inset * result = new InsetCollapsable(buffer);
40 int InsetCollapsable::ascent_collapsed(Painter & pain, LyXFont const &) const
42 int width = 0, ascent = 0, descent = 0;
43 pain.buttonText(0, 0, label.c_str(), labelfont, false,
44 width, ascent, descent);
49 int InsetCollapsable::descent_collapsed(Painter & pain, LyXFont const &) const
51 int width = 0, ascent = 0, descent = 0;
52 pain.buttonText(0, 0, label.c_str(), labelfont, false,
53 width, ascent, descent);
58 int InsetCollapsable::width_collapsed(Painter & pain, LyXFont const &) const
60 int width, ascent, descent;
61 pain.buttonText(TEXT_TO_INSET_OFFSET, 0, label.c_str(), labelfont, false,
62 width, ascent, descent);
63 return width + (2*TEXT_TO_INSET_OFFSET);
67 int InsetCollapsable::ascent(Painter & pain, LyXFont const & font) const
70 return ascent_collapsed(pain, font);
72 return InsetText::ascent(pain, font) + TEXT_TO_TOP_OFFSET;
76 int InsetCollapsable::descent(Painter & pain, LyXFont const & font) const
79 return descent_collapsed(pain, font);
81 return InsetText::descent(pain, font) + TEXT_TO_BOTTOM_OFFSET;
85 int InsetCollapsable::width(Painter & pain, LyXFont const & font) const
88 return width_collapsed(pain, font);
90 return getMaxWidth(pain);
94 void InsetCollapsable::draw_collapsed(Painter & pain, LyXFont const &,
95 int baseline, float & x) const
98 pain.buttonText(int(x) + TEXT_TO_INSET_OFFSET, baseline,
99 label.c_str(), labelfont, true, width);
100 x += width + (2 * TEXT_TO_INSET_OFFSET);
104 void InsetCollapsable::draw(Painter & pain, LyXFont const & f,
105 int baseline, float & x) const
108 draw_collapsed(pain, f, baseline, x);
112 top_baseline = baseline;
113 draw_collapsed(pain, f, baseline, x);
114 button_x = int(x - top_x);
116 maxWidth = getMaxWidth(pain) - button_x;
119 w = maxWidth - widthOffset,
120 h = ascent(pain,f) + descent(pain,f);
122 pain.rectangle(int(x), baseline - ascent(pain, f), w, h, framecolor);
125 top_x = int(x - top_x);
126 InsetText::draw(pain, f, baseline, x);
130 void InsetCollapsable::Edit(BufferView *bv, int x, int y, unsigned int button)
134 UpdateLocal(bv, true);
135 InsetText::Edit(bv, 0, 0, button);
136 } else if (button && (x < button_x) &&
137 (y < (labelfont.maxDescent()+labelfont.maxAscent()))) {
139 UpdateLocal(bv, false);
140 bv->unlockInset(this);
142 InsetText::Edit(bv, x-top_x, y, button);
147 Inset::EDITABLE InsetCollapsable::Editable() const
151 return HIGHLY_EDITABLE;
154 void InsetCollapsable::InsetUnlock(BufferView *bv)
159 InsetText::InsetUnlock(bv);
160 UpdateLocal(bv, true);
164 void InsetCollapsable::UpdateLocal(BufferView *bv, bool flag)
166 maxWidth = getMaxWidth(bv->getPainter()) -
167 width_collapsed(bv->getPainter(), labelfont);
168 InsetText::UpdateLocal(bv, flag);
172 void InsetCollapsable::InsetButtonPress(BufferView *bv,int x,int y,int button)
174 if ((x < button_x) &&
175 (y < (labelfont.maxDescent()+labelfont.maxAscent()))) {
177 UpdateLocal(bv, false);
178 bv->unlockInset(this);
179 } else if (x >= button_x) {
180 InsetText::InsetButtonPress(bv, x-top_x, y, button);
185 void InsetCollapsable::InsetButtonRelease(BufferView *bv, int x, int y, int button)
188 InsetText::InsetButtonRelease(bv, x-top_x, y, button);
192 void InsetCollapsable::InsetMotionNotify(BufferView *bv, int x, int y, int button)
195 InsetText::InsetMotionNotify(bv, x-top_x, y, button);