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)
30 framecolor = LColor::footnoteframe;
32 button_x = button_top_y = button_bottom_y = top_x = -1;
36 Inset * InsetCollapsable::Clone() const
38 InsetCollapsable * result = new InsetCollapsable(buffer);
39 result->init(buffer, par);
41 result->collapsed = collapsed;
45 int InsetCollapsable::ascent_collapsed(Painter & pain, LyXFont const &) const
47 int width = 0, ascent = 0, descent = 0;
48 pain.buttonText(0, 0, label.c_str(), labelfont, false,
49 width, ascent, descent);
54 int InsetCollapsable::descent_collapsed(Painter & pain, LyXFont const &) const
56 int width = 0, ascent = 0, descent = 0;
57 pain.buttonText(0, 0, label.c_str(), labelfont, false,
58 width, ascent, descent);
63 int InsetCollapsable::width_collapsed(Painter & pain, LyXFont const &) const
65 int width, ascent, descent;
66 pain.buttonText(TEXT_TO_INSET_OFFSET, 0, label.c_str(), labelfont, false,
67 width, ascent, descent);
68 return width + (2*TEXT_TO_INSET_OFFSET);
72 int InsetCollapsable::ascent(Painter & pain, LyXFont const & font) const
75 return ascent_collapsed(pain, font);
77 return InsetText::ascent(pain, font) + TEXT_TO_TOP_OFFSET;
81 int InsetCollapsable::descent(Painter & pain, LyXFont const & font) const
84 return descent_collapsed(pain, font);
86 return InsetText::descent(pain, font) + TEXT_TO_BOTTOM_OFFSET;
90 int InsetCollapsable::width(Painter & pain, LyXFont const & font) const
93 return width_collapsed(pain, font);
95 return getMaxWidth(pain) - widthOffset + 2;
99 void InsetCollapsable::draw_collapsed(Painter & pain, LyXFont const &,
100 int baseline, float & x) const
103 pain.buttonText(int(x) + TEXT_TO_INSET_OFFSET, baseline,
104 label.c_str(), labelfont, true, width);
105 x += width + (2 * TEXT_TO_INSET_OFFSET);
109 void InsetCollapsable::draw(Painter & pain, LyXFont const & f,
110 int baseline, float & x) const
113 draw_collapsed(pain, f, baseline, x);
117 top_baseline = baseline;
118 draw_collapsed(pain, f, baseline, x);
120 button_top_y = -ascent_collapsed(pain, f);
121 button_bottom_y = descent_collapsed(pain, f);
123 maxWidth = getMaxWidth(pain) - button_x;
126 w = maxWidth - widthOffset,
127 h = ascent(pain,f) + descent(pain,f);
129 pain.rectangle(int(x), baseline - ascent(pain, f), w, h, framecolor);
132 top_x = int(x - top_x);
133 InsetText::draw(pain, f, baseline, x);
137 void InsetCollapsable::Edit(BufferView *bv, int x, int y, unsigned int button)
141 UpdateLocal(bv, true);
142 InsetText::Edit(bv, 0, 0, button);
143 } else if (button && (x < button_x)) {
146 InsetText::Edit(bv, x-top_x, y, button);
151 Inset::EDITABLE InsetCollapsable::Editable() const
155 return HIGHLY_EDITABLE;
158 void InsetCollapsable::InsetUnlock(BufferView *bv)
163 InsetText::InsetUnlock(bv);
164 UpdateLocal(bv, true);
168 void InsetCollapsable::UpdateLocal(BufferView * bv, bool flag)
170 maxWidth = getMaxWidth(bv->painter()) -
171 width_collapsed(bv->painter(), labelfont);
172 InsetText::UpdateLocal(bv, flag);
176 void InsetCollapsable::InsetButtonPress(BufferView *bv,int x,int y,int button)
178 if ((x >= button_x) && (y >= button_top_y)) {
179 InsetText::InsetButtonPress(bv, x-top_x, y, button);
184 void InsetCollapsable::InsetButtonRelease(BufferView *bv, int x, int y, int button)
186 if ((x < button_x) && (y >= button_top_y) && (y <= button_bottom_y)) {
188 UpdateLocal(bv, false);
189 bv->unlockInset(this);
190 } else if ((x >= button_x) && (y >= button_top_y)) {
191 InsetText::InsetButtonRelease(bv, x-top_x, y, button);
196 void InsetCollapsable::InsetMotionNotify(BufferView *bv, int x, int y, int button)
198 if ((x >= button_x) && (y >= button_top_y)) {
199 InsetText::InsetMotionNotify(bv, x-top_x, y, button);