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;
31 button_x = button_top_y = button_bottom_y = top_x = -1;
35 Inset * InsetCollapsable::Clone() const
37 Inset * result = new InsetCollapsable(buffer);
41 int InsetCollapsable::ascent_collapsed(Painter & pain, LyXFont const &) const
43 int width = 0, ascent = 0, descent = 0;
44 pain.buttonText(0, 0, label.c_str(), labelfont, false,
45 width, ascent, descent);
50 int InsetCollapsable::descent_collapsed(Painter & pain, LyXFont const &) const
52 int width = 0, ascent = 0, descent = 0;
53 pain.buttonText(0, 0, label.c_str(), labelfont, false,
54 width, ascent, descent);
59 int InsetCollapsable::width_collapsed(Painter & pain, LyXFont const &) const
61 int width, ascent, descent;
62 pain.buttonText(TEXT_TO_INSET_OFFSET, 0, label.c_str(), labelfont, false,
63 width, ascent, descent);
64 return width + (2*TEXT_TO_INSET_OFFSET);
68 int InsetCollapsable::ascent(Painter & pain, LyXFont const & font) const
71 return ascent_collapsed(pain, font);
73 return InsetText::ascent(pain, font) + TEXT_TO_TOP_OFFSET;
77 int InsetCollapsable::descent(Painter & pain, LyXFont const & font) const
80 return descent_collapsed(pain, font);
82 return InsetText::descent(pain, font) + TEXT_TO_BOTTOM_OFFSET;
86 int InsetCollapsable::width(Painter & pain, LyXFont const & font) const
89 return width_collapsed(pain, font);
91 return getMaxWidth(pain) - widthOffset + 2;
95 void InsetCollapsable::draw_collapsed(Painter & pain, LyXFont const &,
96 int baseline, float & x) const
99 pain.buttonText(int(x) + TEXT_TO_INSET_OFFSET, baseline,
100 label.c_str(), labelfont, true, width);
101 x += width + (2 * TEXT_TO_INSET_OFFSET);
105 void InsetCollapsable::draw(Painter & pain, LyXFont const & f,
106 int baseline, float & x) const
109 draw_collapsed(pain, f, baseline, x);
113 top_baseline = baseline;
114 draw_collapsed(pain, f, baseline, x);
116 button_top_y = -ascent_collapsed(pain, f);
117 button_bottom_y = descent_collapsed(pain, f);
119 maxWidth = getMaxWidth(pain) - button_x;
122 w = maxWidth - widthOffset,
123 h = ascent(pain,f) + descent(pain,f);
125 pain.rectangle(int(x), baseline - ascent(pain, f), w, h, framecolor);
128 top_x = int(x - top_x);
129 InsetText::draw(pain, f, baseline, x);
133 void InsetCollapsable::Edit(BufferView *bv, int x, int y, unsigned int button)
137 UpdateLocal(bv, true);
138 InsetText::Edit(bv, 0, 0, button);
139 } else if (button && (x < button_x)) {
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) && (y >= button_top_y)) {
175 InsetText::InsetButtonPress(bv, x-top_x, y, button);
180 void InsetCollapsable::InsetButtonRelease(BufferView *bv, int x, int y, int button)
182 if ((x < button_x) && (y >= button_top_y) && (y <= button_bottom_y)) {
184 UpdateLocal(bv, false);
185 bv->unlockInset(this);
186 } else if ((x >= button_x) && (y >= button_top_y)) {
187 InsetText::InsetButtonRelease(bv, x-top_x, y, button);
192 void InsetCollapsable::InsetMotionNotify(BufferView *bv, int x, int y, int button)
194 if ((x >= button_x) && (y >= button_top_y)) {
195 InsetText::InsetMotionNotify(bv, x-top_x, y, button);