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 InsetCollapsable * result = new InsetCollapsable(buffer);
38 result->init(buffer, par);
43 int InsetCollapsable::ascent_collapsed(Painter & pain, LyXFont const &) const
45 int width = 0, ascent = 0, descent = 0;
46 pain.buttonText(0, 0, label.c_str(), labelfont, false,
47 width, ascent, descent);
52 int InsetCollapsable::descent_collapsed(Painter & pain, LyXFont const &) const
54 int width = 0, ascent = 0, descent = 0;
55 pain.buttonText(0, 0, label.c_str(), labelfont, false,
56 width, ascent, descent);
61 int InsetCollapsable::width_collapsed(Painter & pain, LyXFont const &) const
63 int width, ascent, descent;
64 pain.buttonText(TEXT_TO_INSET_OFFSET, 0, label.c_str(), labelfont, false,
65 width, ascent, descent);
66 return width + (2*TEXT_TO_INSET_OFFSET);
70 int InsetCollapsable::ascent(Painter & pain, LyXFont const & font) const
73 return ascent_collapsed(pain, font);
75 return InsetText::ascent(pain, font) + TEXT_TO_TOP_OFFSET;
79 int InsetCollapsable::descent(Painter & pain, LyXFont const & font) const
82 return descent_collapsed(pain, font);
84 return InsetText::descent(pain, font) + TEXT_TO_BOTTOM_OFFSET;
88 int InsetCollapsable::width(Painter & pain, LyXFont const & font) const
91 return width_collapsed(pain, font);
93 return getMaxWidth(pain) - widthOffset + 2;
97 void InsetCollapsable::draw_collapsed(Painter & pain, LyXFont const &,
98 int baseline, float & x) const
101 pain.buttonText(int(x) + TEXT_TO_INSET_OFFSET, baseline,
102 label.c_str(), labelfont, true, width);
103 x += width + (2 * TEXT_TO_INSET_OFFSET);
107 void InsetCollapsable::draw(Painter & pain, LyXFont const & f,
108 int baseline, float & x) const
111 draw_collapsed(pain, f, baseline, x);
115 top_baseline = baseline;
116 draw_collapsed(pain, f, baseline, x);
118 button_top_y = -ascent_collapsed(pain, f);
119 button_bottom_y = descent_collapsed(pain, f);
121 maxWidth = getMaxWidth(pain) - button_x;
124 w = maxWidth - widthOffset,
125 h = ascent(pain,f) + descent(pain,f);
127 pain.rectangle(int(x), baseline - ascent(pain, f), w, h, framecolor);
130 top_x = int(x - top_x);
131 InsetText::draw(pain, f, baseline, x);
135 void InsetCollapsable::Edit(BufferView *bv, int x, int y, unsigned int button)
139 UpdateLocal(bv, true);
140 InsetText::Edit(bv, 0, 0, button);
141 } else if (button && (x < button_x)) {
144 InsetText::Edit(bv, x-top_x, y, button);
149 Inset::EDITABLE InsetCollapsable::Editable() const
153 return HIGHLY_EDITABLE;
156 void InsetCollapsable::InsetUnlock(BufferView *bv)
161 InsetText::InsetUnlock(bv);
162 UpdateLocal(bv, true);
166 void InsetCollapsable::UpdateLocal(BufferView *bv, bool flag)
168 maxWidth = getMaxWidth(bv->getPainter()) -
169 width_collapsed(bv->getPainter(), labelfont);
170 InsetText::UpdateLocal(bv, flag);
174 void InsetCollapsable::InsetButtonPress(BufferView *bv,int x,int y,int button)
176 if ((x >= button_x) && (y >= button_top_y)) {
177 InsetText::InsetButtonPress(bv, x-top_x, y, button);
182 void InsetCollapsable::InsetButtonRelease(BufferView *bv, int x, int y, int button)
184 if ((x < button_x) && (y >= button_top_y) && (y <= button_bottom_y)) {
186 UpdateLocal(bv, false);
187 bv->unlockInset(this);
188 } else if ((x >= button_x) && (y >= button_top_y)) {
189 InsetText::InsetButtonRelease(bv, x-top_x, y, button);
194 void InsetCollapsable::InsetMotionNotify(BufferView *bv, int x, int y, int button)
196 if ((x >= button_x) && (y >= button_top_y)) {
197 InsetText::InsetMotionNotify(bv, x-top_x, y, button);