+int wxToolBar::FindIndexForWidget(WXWidget w)
+{
+ wxNode* node = m_widgets.First();
+ while (node)
+ {
+ WXWidget widget = (WXWidget) node->Data();
+ if (widget == w)
+ return (int) node->GetKeyInteger();
+ node = node->Next();
+ }
+ return -1;
+}
+
+WXWidget wxToolBar::FindWidgetForIndex(int index)
+{
+ wxNode* node = m_widgets.Find((long) index);
+ if (!node)
+ return (WXWidget) 0;
+ else
+ return (WXWidget) node->Data();
+}
+
+WXWidget wxToolBar::GetTopWidget() const
+{
+ return m_mainWidget;
+}
+
+WXWidget wxToolBar::GetClientWidget() const
+{
+ return m_mainWidget;
+}
+
+WXWidget wxToolBar::GetMainWidget() const
+{
+ return m_mainWidget;
+}
+
+
+void wxToolButtonCallback (Widget w, XtPointer clientData,
+ XtPointer ptr)
+{
+ wxToolBar *toolBar = (wxToolBar *) clientData;
+ int index = toolBar->FindIndexForWidget((WXWidget) w);
+
+ if (index != -1)
+ {
+ wxNode *node = toolBar->GetTools().Find((long)index);
+ if (!node)
+ return;
+ wxToolBarTool *tool = (wxToolBarTool *)node->Data();
+ if (tool->m_isToggle)
+ tool->m_toggleState = !tool->m_toggleState;
+
+ (void) toolBar->OnLeftClick(index, tool->m_toggleState);
+ }
+
+}
+
+
+static void wxToolButtonPopupCallback (Widget w, XtPointer client_data,
+ XEvent *event, Boolean *continue_to_dispatch)
+{
+ // TODO: retrieve delay before popping up tooltip from wxSystemSettings.
+ int delayMilli = 800;
+ wxToolBar* toolBar = (wxToolBar*) client_data;
+
+ int index = toolBar->FindIndexForWidget((WXWidget) w);
+
+ if (index != -1)
+ {
+ wxNode *node = toolBar->GetTools().Find((long)index);
+ if (!node)
+ return;
+ wxString str(toolBar->GetToolShortHelp(index));
+ if (str.IsNull() || str == "")
+ return;
+
+ if (!wxTheToolBarTimer)
+ wxTheToolBarTimer = new wxToolBarTimer;
+
+ wxToolBarTimer::buttonWidget = w;
+ wxToolBarTimer::helpString = str;
+
+
+ /************************************************************/
+ /* Popup help label */
+ /************************************************************/
+ if (event->type == EnterNotify)
+ {
+ if (wxToolBarTimer::help_popup != (Widget) 0)
+ {
+ XtDestroyWidget (wxToolBarTimer::help_popup);
+ XtPopdown (wxToolBarTimer::help_popup);
+ }
+ wxToolBarTimer::help_popup = (Widget) 0;
+
+ // One shot
+ wxTheToolBarTimer->Start(delayMilli, TRUE);
+
+ }
+ /************************************************************/
+ /* Popdown help label */
+ /************************************************************/
+ else if (event->type == LeaveNotify)
+ {
+ if (wxTheToolBarTimer)
+ wxTheToolBarTimer->Stop();
+ if (wxToolBarTimer::help_popup != (Widget) 0)
+ {
+ XtDestroyWidget (wxToolBarTimer::help_popup);
+ XtPopdown (wxToolBarTimer::help_popup);
+ }
+ wxToolBarTimer::help_popup = (Widget) 0;
+ }
+ }
+}
+
+void wxToolBarTimer::Notify()
+{
+ Position x, y;
+
+ /************************************************************/
+ /* Create shell without window decorations */
+ /************************************************************/
+ help_popup = XtVaCreatePopupShell ("shell",
+ overrideShellWidgetClass, (Widget) wxTheApp->GetTopLevelWidget(),
+ NULL);
+
+ /************************************************************/
+ /* Get absolute position on display of toolbar button */
+ /************************************************************/
+ XtTranslateCoords (buttonWidget,
+ (Position) 0,
+ (Position) 0,
+ &x, &y);
+
+ // Move the tooltip more or less above the button
+ int yOffset = 20; // TODO: What should be really?
+ y -= yOffset;
+ if (y < yOffset) y = 0;
+
+ /************************************************************/
+ /* Set the position of the help popup */
+ /************************************************************/
+ XtVaSetValues (help_popup,
+ XmNx, (Position) x,
+ XmNy, (Position) y,
+ NULL);
+
+ /************************************************************/
+ /* Create help label */
+ /************************************************************/
+ XmString text = XmStringCreateSimple ((char*) (const char*) helpString);
+ XtVaCreateManagedWidget ("help_label",
+ xmLabelWidgetClass, help_popup,
+ XmNlabelString, text,
+ XtVaTypedArg,
+ XmNforeground, XtRString, "black",
+ strlen("black")+1,
+ XtVaTypedArg,
+ XmNbackground, XtRString, "LightGoldenrod",
+ strlen("LightGoldenrod")+1,
+ NULL);
+ XmStringFree (text);
+
+ /************************************************************/
+ /* Popup help label */
+ /************************************************************/
+ XtPopup (help_popup, XtGrabNone);
+}
+