10 public class ToolTip : Window
12 borderStyle = contour;
13 background = lightYellow;
17 creationActivation = doNothing;
22 bool (* OrigOnMouseOver)(Window window, int x, int y, Modifiers mods);
23 bool (* OrigOnMouseLeave)(Window window, Modifiers mods);
24 bool (* OrigOnMouseMove)(Window window, int x, int y, Modifiers mods);
25 bool (* OrigOnLeftButtonDown)(Window window, int x, int y, Modifiers mods);
28 Array<ToolTipTextLine> lines { };
30 int margin; margin = 2;
31 Point offset; offset = { 0, 20 };
33 public property const String tip
45 tip = CopyString(value);
47 for(c = 0; (ch = next); c++)
50 if(ch == '\n' || next == '\0')
52 lines.Add({ tip + start, c - start + (next == '\0') });
64 display.FontExtent(fontObject, " ", 1, null, &lh);
68 display.FontExtent(fontObject, l.string, l.len, &w, null);
70 if(w > maxW) maxW = w;
72 clientSize = { maxW + 2*margin, lh * lines.count + 2*margin };
76 bool OnMouseLeave(Modifiers mods)
82 bool OnMouseOver(int x, int y, Modifiers mods)
88 bool OnLeftButtonDown(int x, int y, Modifiers mods)
96 this, 0.5, userData = this;
103 pos.x + offset.x + tippedWindow.clientStart.x +
104 tippedWindow.absPosition.x - parent.position.x;
105 pos.y + offset.y + tippedWindow.clientStart.y +
106 tippedWindow.absPosition.y - parent.position.y;
115 this, 0.3, userData = this;
128 if(tippedWindow && tippedWindow == master)
130 tippedWindow.OnMouseOver = OrigOnMouseOver;
131 tippedWindow.OnMouseLeave = OrigOnMouseLeave;
132 tippedWindow.OnMouseMove = OrigOnMouseMove;
133 tippedWindow.OnLeftButtonDown = OrigOnLeftButtonDown;
137 if(parent && parent.parent)
139 Window value = parent;
141 tippedWindow = value;
143 master = tippedWindow;
144 OrigOnMouseOver = value.OnMouseOver;
145 OrigOnMouseLeave = value.OnMouseLeave;
146 OrigOnMouseMove = value.OnMouseMove;
147 OrigOnLeftButtonDown = value.OnLeftButtonDown;
148 tippedWindow.OnMouseOver = OnMouseOverHandler;
149 tippedWindow.OnMouseLeave = OnMouseLeaveHandler;
150 tippedWindow.OnMouseMove = OnMouseMoveHandler;
151 tippedWindow.OnLeftButtonDown = OnLeftButtonDownHandler;
160 tippedWindow.OnMouseOver = OrigOnMouseOver;
161 tippedWindow.OnMouseLeave = OrigOnMouseLeave;
162 tippedWindow.OnMouseMove = OrigOnMouseMove;
163 tippedWindow.OnLeftButtonDown = OrigOnLeftButtonDown;
169 ToolTip ::Find(Window window)
172 for(w = window.firstSlave; w; w = w.nextSlave)
174 if(eClass_IsDerived(w._class, class(ToolTip)))
180 bool Window::OnMouseOverHandler(int x, int y, Modifiers mods)
182 ToolTip toolTip = ToolTip::Find(this);
185 toolTip.pos = { x, y };
186 toolTip.closeTimer.Stop();
187 if(!mods.isSideEffect && !toolTip.created && rootWindow.active && !mods.left)
188 toolTip.timer.Start();
189 return toolTip.OrigOnMouseOver ? toolTip.OrigOnMouseOver(this, x, y, mods) : true;
194 bool Window::OnMouseLeaveHandler(Modifiers mods)
196 ToolTip toolTip = ToolTip::Find(this);
199 toolTip.timer.Stop();
200 toolTip.closeTimer.Start();
201 return toolTip.OrigOnMouseLeave ? toolTip.OrigOnMouseLeave(this, mods) : true;
206 bool Window::OnLeftButtonDownHandler(int x, int y, Modifiers mods)
208 ToolTip toolTip = ToolTip::Find(this);
211 toolTip.timer.Stop();
213 return toolTip.OrigOnLeftButtonDown ? toolTip.OrigOnLeftButtonDown(this, x, y, mods) : true;
218 bool Window::OnMouseMoveHandler(int x, int y, Modifiers mods)
220 ToolTip toolTip = ToolTip::Find(this);
223 toolTip.pos = { x, y };
224 toolTip.closeTimer.Stop();
225 if(!mods.isSideEffect && !toolTip.created && rootWindow.active && !mods.left)
227 toolTip.timer.Stop();
228 toolTip.timer.Start();
230 return toolTip.OrigOnMouseMove ? toolTip.OrigOnMouseMove(this, x, y, mods) : true;
235 void OnRedraw(Surface surface)
240 surface.WriteText(margin, y, l.string, l.len);
246 // NOTE: I'm putting this here for now because I don't have time to update all the makefiles right now
249 public class ToolBar : Stacker
251 direction = horizontal;
252 background = formColor;
256 anchor = Anchor { left = 0, right = 0 };
257 clientSize = { h = 32 };
263 for(w = firstChild; w; w = w.next)
268 public class ToolButton : Button
271 size = Size { 24, 24 };
273 bitmapAlignment = center;
274 MenuItem * menuItemPtr;
280 Window master = this.master;
281 if(master && master.parent && !eClass_IsDerived(master._class, class(Stacker)))
283 MenuItem menuItem = this.menuItem;
286 if(menuItem && (bmp = menuItem.bitmap))
289 // We cannot reuse the same BitmapResource object here, as a BitmapResource is meant to be added with AddResource to a single Window
290 bitmap = { fileName = bmp.fileName, grayed = bmp.grayed, monochrome = bmp.monochrome, transparent = bmp.transparent, alphaBlend = bmp.alphaBlend, keepData = bmp.keepData };
296 NotifyClicked = SelectMenuItem;
298 bool Window::SelectMenuItem(Button button, int x, int y, Modifiers mods)
300 ToolButton toolButton = (ToolButton)button;
301 MenuItem menuItem = toolButton.menuItem;
302 return menuItem ? menuItem.NotifySelect(this, menuItem, 0) : 0;
306 property MenuItem * menuItemPtr { set { menuItemPtr = value; } }
307 property MenuItem menuItem
311 MenuItem menuItem = menuItemPtr ? *(MenuItem *)((byte *)master + (uintptr)menuItemPtr) : null;
317 public class ToolSeparator : Window
319 size = Size { 4, 24 };
322 void OnRedraw(Surface surface)
324 surface.foreground = Color { 85, 85, 85 };
325 surface.VLine(0, 23, 1);
326 surface.foreground = white;
327 surface.VLine(0, 23, 2);