2. Motif warnings removed
3. Using native msgbox under Motif (ok, it doesn't work, but generic doesn't
   work neither)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2930 
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
 // Name:        gridg.h
 // Purpose:     wxGenericGrid
 // Author:      Julian Smart
 // Name:        gridg.h
 // Purpose:     wxGenericGrid
 // Author:      Julian Smart
-// Modified by: Michael Bedward 
+// Modified by: Michael Bedward
 //                Added edit in place facility, 20 April 1999
 //                Added cursor key control, 29 Jun 1999
 // Created:     01/02/97
 //                Added edit in place facility, 20 April 1999
 //                Added cursor key control, 29 Jun 1999
 // Created:     01/02/97
     void SetCellTextFont(const wxFont& fnt, int row, int col);
     wxBitmap *GetCellBitmap(int row, int col) const;
     void SetCellBitmap(wxBitmap *bitmap, int row, int col);
     void SetCellTextFont(const wxFont& fnt, int row, int col);
     wxBitmap *GetCellBitmap(int row, int col) const;
     void SetCellBitmap(wxBitmap *bitmap, int row, int col);
+    void *SetCellData(void *data, int row, int col);
+    void *GetCellData(int row, int col);
 
     // Size accessors
     void SetColumnWidth(int col, int width);
     int GetColumnWidth(int col) const;
     void SetRowHeight(int row, int height);
     int GetRowHeight(int row) const;
 
     // Size accessors
     void SetColumnWidth(int col, int width);
     int GetColumnWidth(int col) const;
     void SetRowHeight(int row, int height);
     int GetRowHeight(int row) const;
+    int GetViewHeight() const { return m_viewHeight; }
+    int GetViewWidth() const { return m_viewWidth; }
 
     // Label accessors
     void SetLabelSize(int orientation, int sz);
 
     // Label accessors
     void SetLabelSize(int orientation, int sz);
     int                       m_bottomOfSheet;   // Calculated from m_rowHeights
     int                       m_totalGridWidth; // Total 'virtual' size
     int                       m_totalGridHeight;
     int                       m_bottomOfSheet;   // Calculated from m_rowHeights
     int                       m_totalGridWidth; // Total 'virtual' size
     int                       m_totalGridHeight;
+    int                       m_viewHeight;        // Number of rows displayed
+    int                       m_viewWidth;        // Number of columns displayed
     int                       m_cellHeight;      // For now, a default
     int                       m_verticalLabelWidth;
     int                       m_horizontalLabelHeight;
     int                       m_cellHeight;      // For now, a default
     int                       m_verticalLabelWidth;
     int                       m_horizontalLabelHeight;
     wxColour  backgroundColour;
     wxBrush   backgroundBrush;
     wxBitmap* cellBitmap;
     wxColour  backgroundColour;
     wxBrush   backgroundBrush;
     wxBitmap* cellBitmap;
+    void*     cellData;        // intended for additional data associated with a cell
+    int       alignment;
 
     wxGridCell(wxGenericGrid *window = (wxGenericGrid *) NULL);
     ~wxGridCell();
 
     wxGridCell(wxGenericGrid *window = (wxGenericGrid *) NULL);
     ~wxGridCell();
     void SetAlignment(int align) { alignment = align; }
     wxBitmap *GetCellBitmap() const { return cellBitmap; }
     void SetCellBitmap(wxBitmap *bitmap) { cellBitmap = bitmap; }
     void SetAlignment(int align) { alignment = align; }
     wxBitmap *GetCellBitmap() const { return cellBitmap; }
     void SetCellBitmap(wxBitmap *bitmap) { cellBitmap = bitmap; }
+
+    void *SetCellData(void *data) { void *rc = cellData; cellData = data; return rc; }
+    void *GetCellData() const { return cellData; }
 };
 
 class WXDLLEXPORT wxGrid : public wxGenericGrid
 };
 
 class WXDLLEXPORT wxGrid : public wxGenericGrid
 
 #if defined(__WXMSW__)
 #include "wx/msw/msgdlg.h"
 #elif defined(__WXMOTIF__)
 #if defined(__WXMSW__)
 #include "wx/msw/msgdlg.h"
 #elif defined(__WXMOTIF__)
-#include "wx/generic/msgdlgg.h"
+#include "wx/motif/msgdlg.h"
 #elif defined(__WXGTK__)
 #include "wx/gtk/msgdlg.h"
 #elif defined(__WXQT__)
 #elif defined(__WXGTK__)
 #include "wx/gtk/msgdlg.h"
 #elif defined(__WXQT__)
 
 // Modified by: Michael Bedward
 //                Added edit in place facility, 20 Apr 1999
 //                Added cursor key control, 29 Jun 1999
 // Modified by: Michael Bedward
 //                Added edit in place facility, 20 Apr 1999
 //                Added cursor key control, 29 Jun 1999
+//              Gerhard Gruber
+//                Added keyboard navigation, client data, other fixes
 // Created:     04/01/98
 // RCS-ID:      $Id$
 // Copyright:   (c) Julian Smart and Markus Holzem
 // Created:     04/01/98
 // RCS-ID:      $Id$
 // Copyright:   (c) Julian Smart and Markus Holzem
-wxGenericGrid::wxGenericGrid(void)
+wxGenericGrid::wxGenericGrid()
+  m_viewWidth = 0;
+  m_viewHeight = 0;
   m_batchCount = 0;
   m_hScrollBar = (wxScrollBar *) NULL;
   m_vScrollBar = (wxScrollBar *) NULL;
   m_batchCount = 0;
   m_hScrollBar = (wxScrollBar *) NULL;
   m_vScrollBar = (wxScrollBar *) NULL;
   m_textItem = (wxTextCtrl *) NULL;
 }
 
   m_textItem = (wxTextCtrl *) NULL;
 }
 
-bool wxGenericGrid::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
- long style, const wxString& name)
+bool wxGenericGrid::Create(wxWindow *parent,
+                           wxWindowID id,
+                           const wxPoint& pos,
+                           const wxSize& size,
+                           long style,
+                           const wxString& name)
+  m_viewWidth = 0;
+  m_viewHeight = 0;
   m_batchCount = 0;
   m_editingPanel = (wxPanel *) NULL;
   m_hScrollBar = (wxScrollBar *) NULL;
   m_batchCount = 0;
   m_editingPanel = (wxPanel *) NULL;
   m_hScrollBar = (wxScrollBar *) NULL;
-wxGenericGrid::~wxGenericGrid(void)
+wxGenericGrid::~wxGenericGrid()
-void wxGenericGrid::ClearGrid(void)
+void wxGenericGrid::ClearGrid()
 {
   int i,j;
   if (m_gridCells)
 {
   int i,j;
   if (m_gridCells)
 }
 
 // Need to determine various dimensions
 }
 
 // Need to determine various dimensions
-void wxGenericGrid::UpdateDimensions(void)
+void wxGenericGrid::UpdateDimensions()
 {
   int canvasWidth, canvasHeight;
   GetSize(&canvasWidth, &canvasHeight);
 {
   int canvasWidth, canvasHeight;
   GetSize(&canvasWidth, &canvasHeight);
-void wxGenericGrid::AdjustScrollbars(void)
+void wxGenericGrid::AdjustScrollbars()
 {
   int cw, ch;
   GetClientSize(&cw, &ch);
 {
   int cw, ch;
   GetClientSize(&cw, &ch);
   int noHorizSteps = 0;
   int noVertSteps = 0;
 
   int noHorizSteps = 0;
   int noVertSteps = 0;
 
-  if (m_totalGridWidth + vertScrollBarWidth <= cw)
-    noHorizSteps = 0;
-  else
+  if (m_totalGridWidth + vertScrollBarWidth > cw)
     int widthCount = 0;
 
     int i;
     int widthCount = 0;
 
     int i;
     for (i = m_scrollPosX ; i < m_totalCols; i++)
     {
       widthCount += m_colWidths[i];
     for (i = m_scrollPosX ; i < m_totalCols; i++)
     {
       widthCount += m_colWidths[i];
-          // A partial bit doesn't count, we still have to scroll to see the
-          // rest of it
+      // A partial bit doesn't count, we still have to scroll to see the
+      // rest of it
       if (widthCount + m_leftOfSheet + m_verticalLabelWidth > (cw-vertScrollBarWidth))
         break;
       if (widthCount + m_leftOfSheet + m_verticalLabelWidth > (cw-vertScrollBarWidth))
         break;
-  if (m_totalGridHeight + horizScrollBarHeight <= ch)
-    noVertSteps = 0;
-  else
+  m_viewWidth = noHorizSteps;
+
+  if (m_totalGridHeight + horizScrollBarHeight > ch)
     int heightCount = 0;
 
     int i;
     int heightCount = 0;
 
     int i;
     for (i = m_scrollPosY ; i < m_totalRows; i++)
     {
       heightCount += m_rowHeights[i];
     for (i = m_scrollPosY ; i < m_totalRows; i++)
     {
       heightCount += m_rowHeights[i];
-          // A partial bit doesn't count, we still have to scroll to see the
-          // rest of it
+      // A partial bit doesn't count, we still have to scroll to see the
+      // rest of it
       if (heightCount + m_topOfSheet + m_horizontalLabelHeight > (ch-horizScrollBarHeight))
         break;
       if (heightCount + m_topOfSheet + m_horizontalLabelHeight > (ch-horizScrollBarHeight))
         break;
+  m_viewHeight = noVertSteps;
+
   if (m_totalGridWidth + vertScrollBarWidth <= cw)
   {
   if (m_totalGridWidth + vertScrollBarWidth <= cw)
   {
-        if ( m_hScrollBar )
-            m_hScrollBar->Show(FALSE);
+    if ( m_hScrollBar )
+        m_hScrollBar->Show(FALSE);
   GetEventHandler()->ProcessEvent(g_evt2);
 }
 
   GetEventHandler()->ProcessEvent(g_evt2);
 }
 
-wxGridCell *wxGenericGrid::OnCreateCell(void)
+wxGridCell *wxGenericGrid::OnCreateCell()
 {
   return new wxGridCell(this);
 }
 
 {
   return new wxGridCell(this);
 }
 
-void wxGenericGrid::OnChangeLabels(void)
+void wxGenericGrid::OnChangeLabels()
-void wxGenericGrid::OnChangeSelectionLabel(void)
+void wxGenericGrid::OnChangeSelectionLabel()
 {
   if (!GetEditable())
     return;
 {
   if (!GetEditable())
     return;
   dc->SetLogicalFunction(wxCOPY);
 }
 
   dc->SetLogicalFunction(wxCOPY);
 }
 
-void wxGenericGrid::DrawCellText(void)
+void wxGenericGrid::DrawCellText()
 {
   if (!m_currentRectVisible)
     return;
 {
   if (!m_currentRectVisible)
     return;
+// ----------------------------------------------------------------------------
+// Grid cell
+// ----------------------------------------------------------------------------
 
 wxGridCell::wxGridCell(wxGenericGrid *window)
 {
 
 wxGridCell::wxGridCell(wxGenericGrid *window)
 {
     alignment = window->GetCellAlignment();
   else
     alignment = wxLEFT;
     alignment = window->GetCellAlignment();
   else
     alignment = wxLEFT;
+
+  cellData = (void *)NULL;
-wxGridCell::~wxGridCell(void)
+wxGridCell::~wxGridCell()
     OnLabelRightClick(ev.m_row, ev.m_col, ev.m_x, ev.m_y, ev.m_control, ev.m_shift);
 }
 
     OnLabelRightClick(ev.m_row, ev.m_col, ev.m_x, ev.m_y, ev.m_control, ev.m_shift);
 }
 
+void *wxGenericGrid::SetCellData(void *data, int row, int col)
+{
+    void *rc = NULL;
+
+    wxGridCell *cell = GetCell(row, col);
+    if ( cell )
+        rc = cell->SetCellData(data);
+
+    return rc;
+}
+
+void *wxGenericGrid::GetCellData(int row, int col)
+{
+    void *rc = NULL;
+
+    wxGridCell *cell = GetCell(row, col);
+    if ( cell )
+        rc = cell->GetCellData();
+
+    return rc;
+}
 
  imaglist.cpp \
  laywin.cpp \
  listctrl.cpp \
  imaglist.cpp \
  laywin.cpp \
  listctrl.cpp \
  panelg.cpp \
  printps.cpp \
  prntdlgg.cpp \
  panelg.cpp \
  printps.cpp \
  prntdlgg.cpp \
  menu.cpp \
  menuitem.cpp \
  minifram.cpp \
  menu.cpp \
  menuitem.cpp \
  minifram.cpp \
  notebook.cpp \
  palette.cpp \
  pen.cpp \
  notebook.cpp \
  palette.cpp \
  pen.cpp \
 
 // Created:     17/09/98
 // RCS-ID:      $Id$
 // Copyright:   (c) Julian Smart
 // Created:     17/09/98
 // RCS-ID:      $Id$
 // Copyright:   (c) Julian Smart
-// Licence:    wxWindows licence
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 
 /////////////////////////////////////////////////////////////////////////////
 
 
     m_noItems = 0;
     m_menuBar = NULL;
     m_pInvokingWindow = NULL;
     m_noItems = 0;
     m_menuBar = NULL;
     m_pInvokingWindow = NULL;
     //// Motif-specific members
     m_numColumns = 1;
     m_menuWidget = (WXWidget) NULL;
     //// Motif-specific members
     m_numColumns = 1;
     m_menuWidget = (WXWidget) NULL;
     m_ownedByMenuBar = FALSE;
     m_menuParent = (wxMenu*) NULL;
     m_clientData = (void*) NULL;
     m_ownedByMenuBar = FALSE;
     m_menuParent = (wxMenu*) NULL;
     m_clientData = (void*) NULL;
     if (m_title != "")
     {
         Append(ID_SEPARATOR, m_title) ;
     if (m_title != "")
     {
         Append(ID_SEPARATOR, m_title) ;
     m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENU);
     m_foregroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENUTEXT);
     m_font = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT);
     m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENU);
     m_foregroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENUTEXT);
     m_font = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT);
         else
             DestroyMenu(FALSE);
     }
         else
             DestroyMenu(FALSE);
     }
     // Not sure if this is right
     if (m_menuParent && m_menuBar)
     {
         m_menuParent = NULL;
         //      m_menuBar = NULL;
     }
     // Not sure if this is right
     if (m_menuParent && m_menuBar)
     {
         m_menuParent = NULL;
         //      m_menuBar = NULL;
     }
     wxNode *node = m_menuItems.First();
     while (node)
     {
         wxMenuItem *item = (wxMenuItem *)node->Data();
     wxNode *node = m_menuItems.First();
     while (node)
     {
         wxMenuItem *item = (wxMenuItem *)node->Data();
         /*
         if (item->GetSubMenu())
         item->DeleteSubMenu();
         */
         /*
         if (item->GetSubMenu())
         item->DeleteSubMenu();
         */
         wxNode *next = node->Next();
         delete item;
         delete node;
         wxNode *next = node->Next();
         delete item;
         delete node;
 void wxMenu::Append(wxMenuItem *pItem)
 {
     wxCHECK_RET( pItem != NULL, "can't append NULL item to the menu" );
 void wxMenu::Append(wxMenuItem *pItem)
 {
     wxCHECK_RET( pItem != NULL, "can't append NULL item to the menu" );
     m_menuItems.Append(pItem);
     m_menuItems.Append(pItem);
-        pItem->CreateItem (m_menuWidget, m_menuBar, m_topLevelMenu);   // this is a dynamic Append
-    
+        pItem->CreateItem (m_menuWidget, m_menuBar, m_topLevelMenu); // this is a dynamic Append
+
 // as well as in m_menuItems, whereas we only store it in
 // m_menuItems here. What implications does this have?
 
 // as well as in m_menuItems, whereas we only store it in
 // m_menuItems here. What implications does this have?
 
-void wxMenu::Append(int id, const wxString& label, wxMenu *subMenu, 
+void wxMenu::Append(int id, const wxString& label, wxMenu *subMenu,
                     const wxString& helpString)
 {
     Append(new wxMenuItem(this, id, label, helpString, FALSE, subMenu));
                     const wxString& helpString)
 {
     Append(new wxMenuItem(this, id, label, helpString, FALSE, subMenu));
     subMenu->m_topLevelMenu = m_topLevelMenu;
 }
 
 // Ordinary menu item
     subMenu->m_topLevelMenu = m_topLevelMenu;
 }
 
 // Ordinary menu item
-void wxMenu::Append(int id, const wxString& label, 
+void wxMenu::Append(int id, const wxString& label,
                     const wxString& helpString, bool checkable)
 {
     // 'checkable' parameter is useless for Windows.
                     const wxString& helpString, bool checkable)
 {
     // 'checkable' parameter is useless for Windows.
     wxNode *node;
     wxMenuItem *item;
     int pos;
     wxNode *node;
     wxMenuItem *item;
     int pos;
-    
-    for (pos = 0, node = m_menuItems.First(); node; node = node->Next(), pos++) 
+
+    for (pos = 0, node = m_menuItems.First(); node; node = node->Next(), pos++)
     {
         item = (wxMenuItem *)node->Data();
         if (item->GetId() == id)
             break;
     }
     {
         item = (wxMenuItem *)node->Data();
         if (item->GetId() == id)
             break;
     }
     // See also old code - don't know if this is needed (seems redundant).
     /*
     if (item->GetSubMenu()) {
     // See also old code - don't know if this is needed (seems redundant).
     /*
     if (item->GetSubMenu()) {
     children->DeleteObject(item->GetSubMenu());
     }
     */
     children->DeleteObject(item->GetSubMenu());
     }
     */
     m_menuItems.DeleteNode(node);
     delete item;
 }
     m_menuItems.DeleteNode(node);
     delete item;
 }
 {
     wxMenuItem *item = FindItemForId(id);
     wxCHECK_RET( item != NULL, "can't enable non-existing menu item" );
 {
     wxMenuItem *item = FindItemForId(id);
     wxCHECK_RET( item != NULL, "can't enable non-existing menu item" );
 {
     wxMenuItem *item = FindItemForId(Id);
     wxCHECK( item != NULL, FALSE );
 {
     wxMenuItem *item = FindItemForId(Id);
     wxCHECK( item != NULL, FALSE );
     return item->IsEnabled();
 }
 
     return item->IsEnabled();
 }
 
 {
     wxMenuItem *item = FindItemForId(Id);
     wxCHECK_RET( item != NULL, "can't get status of non-existing menu item" );
 {
     wxMenuItem *item = FindItemForId(Id);
     wxCHECK_RET( item != NULL, "can't get status of non-existing menu item" );
 {
     wxMenuItem *item = FindItemForId(id);
     wxCHECK( item != NULL, FALSE );
 {
     wxMenuItem *item = FindItemForId(id);
     wxCHECK( item != NULL, FALSE );
     return item->IsChecked();
 }
 
 void wxMenu::SetTitle(const wxString& label)
 {
     m_title = label ;
     return item->IsChecked();
 }
 
 void wxMenu::SetTitle(const wxString& label)
 {
     m_title = label ;
     wxNode *node = m_menuItems.First ();
     if (!node)
         return;
     wxNode *node = m_menuItems.First ();
     if (!node)
         return;
     wxMenuItem *item = (wxMenuItem *) node->Data ();
     Widget widget = (Widget) item->GetButtonWidget();
     if (!widget)
         return;
     wxMenuItem *item = (wxMenuItem *) node->Data ();
     Widget widget = (Widget) item->GetButtonWidget();
     if (!widget)
         return;
     XmString title_str = XmStringCreateSimple ((char*) (const char*) label);
     XtVaSetValues (widget,
         XmNlabelString, title_str,
     XmString title_str = XmStringCreateSimple ((char*) (const char*) label);
     XtVaSetValues (widget,
         XmNlabelString, title_str,
     wxMenuItem *item = FindItemForId(id);
     if (item == (wxMenuItem*) NULL)
         return;
     wxMenuItem *item = FindItemForId(id);
     if (item == (wxMenuItem*) NULL)
         return;
         XtVaGetValues ((Widget) w,
             XmNlabelString, &text,
             NULL);
         XtVaGetValues ((Widget) w,
             XmNlabelString, &text,
             NULL);
         if (XmStringGetLtoR (text, XmSTRING_DEFAULT_CHARSET, &s))
         {
             wxString str(s);
         if (XmStringGetLtoR (text, XmSTRING_DEFAULT_CHARSET, &s))
         {
             wxString str(s);
     char buf1[200];
     char buf2[200];
     wxStripMenuCodes ((char *)(const char *)itemString, buf1);
     char buf1[200];
     char buf2[200];
     wxStripMenuCodes ((char *)(const char *)itemString, buf1);
     for (wxNode * node = m_menuItems.First (); node; node = node->Next ())
     {
         wxMenuItem *item = (wxMenuItem *) node->Data ();
     for (wxNode * node = m_menuItems.First (); node; node = node->Next ())
     {
         wxMenuItem *item = (wxMenuItem *) node->Data ();
                 return item->GetId();
         }
     }
                 return item->GetId();
         }
     }
     for (wxNode * node = m_menuItems.First (); node; node = node->Next ())
     {
         wxMenuItem *item = (wxMenuItem *) node->Data ();
     for (wxNode * node = m_menuItems.First (); node; node = node->Next ())
     {
         wxMenuItem *item = (wxMenuItem *) node->Data ();
         if (item->GetId() == itemId)
         {
             if (itemMenu)
                 *itemMenu = (wxMenu *) this;
             return item;
         }
         if (item->GetId() == itemId)
         {
             if (itemMenu)
                 *itemMenu = (wxMenu *) this;
             return item;
         }
         if (item->GetSubMenu())
         {
             wxMenuItem *ans = item->GetSubMenu()->FindItemForId (itemId, itemMenu);
         if (item->GetSubMenu())
         {
             wxMenuItem *ans = item->GetSubMenu()->FindItemForId (itemId, itemMenu);
     if (itemMenu)
         *itemMenu = NULL;
     return NULL;
     if (itemMenu)
         *itemMenu = NULL;
     return NULL;
 void wxMenu::ProcessCommand(wxCommandEvent & event)
 {
     bool processed = FALSE;
 void wxMenu::ProcessCommand(wxCommandEvent & event)
 {
     bool processed = FALSE;
     // Try a callback
     if (m_callback)
     {
         (void) (*(m_callback)) (*this, event);
         processed = TRUE;
     }
     // Try a callback
     if (m_callback)
     {
         (void) (*(m_callback)) (*this, event);
         processed = TRUE;
     }
     // Try the menu's event handler
     if ( !processed && GetEventHandler())
     {
     // Try the menu's event handler
     if ( !processed && GetEventHandler())
     {
 bool wxWindow::PopupMenu(wxMenu *menu, int x, int y)
 {
     Widget widget = (Widget) GetMainWidget();
 bool wxWindow::PopupMenu(wxMenu *menu, int x, int y)
 {
     Widget widget = (Widget) GetMainWidget();
     /* The menuId field seems to be usused, so we'll use it to
     indicate whether a menu is popped up or not:
     0: Not currently created as a popup
     -1: Created as a popup, but not active
     1: Active popup.
     */
     /* The menuId field seems to be usused, so we'll use it to
     indicate whether a menu is popped up or not:
     0: Not currently created as a popup
     -1: Created as a popup, but not active
     1: Active popup.
     */
     if (menu->GetParent() && (menu->GetId() != -1))
         return FALSE;
     if (menu->GetParent() && (menu->GetId() != -1))
         return FALSE;
     if (menu->GetMainWidget()) {
         menu->DestroyMenu(TRUE);
     }
     if (menu->GetMainWidget()) {
         menu->DestroyMenu(TRUE);
     }
-    
-    wxWindow *parent = this;
-    
     menu->SetId(1); /* Mark as popped-up */
     menu->CreateMenu(NULL, widget, menu);
     menu->SetInvokingWindow(this);
     menu->SetId(1); /* Mark as popped-up */
     menu->CreateMenu(NULL, widget, menu);
     menu->SetInvokingWindow(this);
 
     //  menu->SetParent(parent);
     //  parent->children->Append(menu);  // Store menu for later deletion
 
     //  menu->SetParent(parent);
     //  parent->children->Append(menu);  // Store menu for later deletion
     Widget menuWidget = (Widget) menu->GetMainWidget();
     Widget menuWidget = (Widget) menu->GetMainWidget();
     int rootX = 0;
     int rootY = 0;
     int rootX = 0;
     int rootY = 0;
     int deviceX = x;
     int deviceY = y;
     /*
     int deviceX = x;
     int deviceY = y;
     /*
     deviceY = canvas->GetDC ()->LogicalToDeviceY (y);
     }
     */
     deviceY = canvas->GetDC ()->LogicalToDeviceY (y);
     }
     */
     Display *display = XtDisplay (widget);
     Window rootWindow = RootWindowOfScreen (XtScreen((Widget)widget));
     Window thisWindow = XtWindow (widget);
     Window childWindow;
     XTranslateCoordinates (display, thisWindow, rootWindow, (int) deviceX, (int) deviceY,
         &rootX, &rootY, &childWindow);
     Display *display = XtDisplay (widget);
     Window rootWindow = RootWindowOfScreen (XtScreen((Widget)widget));
     Window thisWindow = XtWindow (widget);
     Window childWindow;
     XTranslateCoordinates (display, thisWindow, rootWindow, (int) deviceX, (int) deviceY,
         &rootX, &rootY, &childWindow);
     XButtonPressedEvent event;
     event.type = ButtonPress;
     event.button = 1;
     XButtonPressedEvent event;
     event.type = ButtonPress;
     event.button = 1;
     event.x = deviceX;
     event.y = deviceY;
     event.x = deviceX;
     event.y = deviceY;
     event.x_root = rootX;
     event.y_root = rootY;
     event.x_root = rootX;
     event.y_root = rootY;
     XmMenuPosition (menuWidget, &event);
     XtManageChild (menuWidget);
     XmMenuPosition (menuWidget, &event);
     XtManageChild (menuWidget);
     wxMenuItem *item = FindItemForId(id, &itemMenu) ;
     if (!item)
         return;
     wxMenuItem *item = FindItemForId(id, &itemMenu) ;
     if (!item)
         return;
     if (!item->IsCheckable())
         return ;
     if (!item->IsCheckable())
         return ;
     wxMenuItem *item = FindItemForId(id, &itemMenu) ;
     if (!item)
         return FALSE;
     wxMenuItem *item = FindItemForId(id, &itemMenu) ;
     if (!item)
         return FALSE;
     return item->IsChecked();
 }
 
     return item->IsChecked();
 }
 
     wxMenuItem *item = FindItemForId(id, &itemMenu) ;
     if (!item)
         return FALSE;
     wxMenuItem *item = FindItemForId(id, &itemMenu) ;
     if (!item)
         return FALSE;
     return item->IsEnabled();
 }
 
     return item->IsEnabled();
 }
 
 {
     wxMenu *itemMenu = NULL;
     wxMenuItem *item = FindItemForId(id, &itemMenu) ;
 {
     wxMenu *itemMenu = NULL;
     wxMenuItem *item = FindItemForId(id, &itemMenu) ;
 {
     wxMenu *itemMenu = NULL;
     wxMenuItem *item = FindItemForId(id, &itemMenu) ;
 {
     wxMenu *itemMenu = NULL;
     wxMenuItem *item = FindItemForId(id, &itemMenu) ;
     if (!item)
         return wxString("");
     if (!item)
         return wxString("");
     return item->GetLabel();
 }
 
 void wxMenuBar::SetLabelTop(int pos, const wxString& label)
 {
     wxASSERT( (pos < m_menuCount) );
     return item->GetLabel();
 }
 
 void wxMenuBar::SetLabelTop(int pos, const wxString& label)
 {
     wxASSERT( (pos < m_menuCount) );
     Widget w = (Widget) m_menus[pos]->GetButtonWidget();
     if (w)
     {
     Widget w = (Widget) m_menus[pos]->GetButtonWidget();
     if (w)
     {
 wxString wxMenuBar::GetLabelTop(int pos) const
 {
     wxASSERT( (pos < m_menuCount) );
 wxString wxMenuBar::GetLabelTop(int pos) const
 {
     wxASSERT( (pos < m_menuCount) );
     Widget w = (Widget) m_menus[pos]->GetButtonWidget();
     if (w)
     {
     Widget w = (Widget) m_menus[pos]->GetButtonWidget();
     if (w)
     {
         XtVaGetValues (w,
             XmNlabelString, &text,
             NULL);
         XtVaGetValues (w,
             XmNlabelString, &text,
             NULL);
         if (XmStringGetLtoR (text, XmSTRING_DEFAULT_CHARSET, &s))
         {
             wxString str(s);
         if (XmStringGetLtoR (text, XmSTRING_DEFAULT_CHARSET, &s))
         {
             wxString str(s);
     }
     else
         return wxEmptyString;
     }
     else
         return wxEmptyString;
 }
 
 bool wxMenuBar::OnDelete(wxMenu *menu, int pos)
 }
 
 bool wxMenuBar::OnDelete(wxMenu *menu, int pos)
     // Only applies to dynamic deletion (when set in frame)
     if (!m_menuBarFrame)
         return TRUE;
     // Only applies to dynamic deletion (when set in frame)
     if (!m_menuBarFrame)
         return TRUE;
     menu->DestroyMenu(TRUE);
     return TRUE;
 }
     menu->DestroyMenu(TRUE);
     return TRUE;
 }
     // Only applies to dynamic append (when set in frame)
     if (!m_menuBarFrame)
         return TRUE;
     // Only applies to dynamic append (when set in frame)
     if (!m_menuBarFrame)
         return TRUE;
     // Probably should be an assert here
     if (menu->GetParent())
         return FALSE;
     // Probably should be an assert here
     if (menu->GetParent())
         return FALSE;
     // Has already been appended
     if (menu->GetButtonWidget())
         return FALSE;
     // Has already been appended
     if (menu->GetButtonWidget())
         return FALSE;
     WXWidget w = menu->CreateMenu(this, GetMainWidget(), menu, title, TRUE);
     menu->SetButtonWidget(w);
     WXWidget w = menu->CreateMenu(this, GetMainWidget(), menu, title, TRUE);
     menu->SetButtonWidget(w);
 {
     if (!OnAppend(menu, title))
         return;
 {
     if (!OnAppend(menu, title))
         return;
     m_menuCount ++;
     wxMenu **new_menus = new wxMenu *[m_menuCount];
     wxString *new_titles = new wxString[m_menuCount];
     int i;
     m_menuCount ++;
     wxMenu **new_menus = new wxMenu *[m_menuCount];
     wxString *new_titles = new wxString[m_menuCount];
     int i;
     for (i = 0; i < m_menuCount - 1; i++)
     {
         new_menus[i] = m_menus[i];
     for (i = 0; i < m_menuCount - 1; i++)
     {
         new_menus[i] = m_menus[i];
     }
     m_menus = new_menus;
     m_titles = new_titles;
     }
     m_menus = new_menus;
     m_titles = new_titles;
     m_menus[m_menuCount - 1] = (wxMenu *)menu;
     m_titles[m_menuCount - 1] = title;
     m_menus[m_menuCount - 1] = (wxMenu *)menu;
     m_titles[m_menuCount - 1] = title;
     menu->SetMenuBar(this);
     menu->SetParent(this);
 }
     menu->SetMenuBar(this);
     menu->SetParent(this);
 }
 {
     int j;
     int ii = (int) i;
 {
     int j;
     int ii = (int) i;
     if (menu != 0)
     {
         for (ii = 0; ii < m_menuCount; ii++)
     if (menu != 0)
     {
         for (ii = 0; ii < m_menuCount; ii++)
             return;
         menu = m_menus[ii];
     }
             return;
         menu = m_menus[ii];
     }
     if (!OnDelete(menu, ii))
         return;
     if (!OnDelete(menu, ii))
         return;
     menu->SetParent((wxEvtHandler*) NULL);
     menu->SetParent((wxEvtHandler*) NULL);
     -- m_menuCount;
     for (j = ii; j < m_menuCount; j++)
     {
     -- m_menuCount;
     for (j = ii; j < m_menuCount; j++)
     {
 {
     if (itemMenu)
         *itemMenu = NULL;
 {
     if (itemMenu)
         *itemMenu = NULL;
     wxMenuItem *item = NULL;
     int i;
     for (i = 0; i < m_menuCount; i++)
     wxMenuItem *item = NULL;
     int i;
     for (i = 0; i < m_menuCount; i++)
         XtMapWidget((Widget) m_mainWidget);
         return TRUE;
     }
         XtMapWidget((Widget) m_mainWidget);
         return TRUE;
     }
     Widget menuBarW = XmCreateMenuBar ((Widget) parent->GetMainWindowWidget(), "MenuBar", NULL, 0);
     m_mainWidget = (WXWidget) menuBarW;
     Widget menuBarW = XmCreateMenuBar ((Widget) parent->GetMainWindowWidget(), "MenuBar", NULL, 0);
     m_mainWidget = (WXWidget) menuBarW;
     int i;
     for (i = 0; i < GetMenuCount(); i++)
     {
         wxMenu *menu = GetMenu(i);
         wxString title(m_titles[i]);
         menu->SetButtonWidget(menu->CreateMenu (this, menuBarW, menu, title, TRUE));
     int i;
     for (i = 0; i < GetMenuCount(); i++)
     {
         wxMenu *menu = GetMenu(i);
         wxString title(m_titles[i]);
         menu->SetButtonWidget(menu->CreateMenu (this, menuBarW, menu, title, TRUE));
         /*
         * COMMENT THIS OUT IF YOU DON'T LIKE A RIGHT-JUSTIFIED HELP MENU
         */
         wxStripMenuCodes ((char*) (const char*) title, wxBuffer);
         /*
         * COMMENT THIS OUT IF YOU DON'T LIKE A RIGHT-JUSTIFIED HELP MENU
         */
         wxStripMenuCodes ((char*) (const char*) title, wxBuffer);
         if (strcmp (wxBuffer, "Help") == 0)
             XtVaSetValues ((Widget) menuBarW, XmNmenuHelpWidget, (Widget) menu->GetButtonWidget(), NULL);
     }
         if (strcmp (wxBuffer, "Help") == 0)
             XtVaSetValues ((Widget) menuBarW, XmNmenuHelpWidget, (Widget) menu->GetButtonWidget(), NULL);
     }
     SetBackgroundColour(m_backgroundColour);
     SetForegroundColour(m_foregroundColour);
     SetFont(m_font);
     SetBackgroundColour(m_backgroundColour);
     SetForegroundColour(m_foregroundColour);
     SetFont(m_font);
     XtVaSetValues((Widget) parent->GetMainWindowWidget(), XmNmenuBar, (Widget) m_mainWidget, NULL);
     XtRealizeWidget ((Widget) menuBarW);
     XtManageChild ((Widget) menuBarW);
     SetMenuBarFrame(parent);
     XtVaSetValues((Widget) parent->GetMainWindowWidget(), XmNmenuBar, (Widget) m_mainWidget, NULL);
     XtRealizeWidget ((Widget) menuBarW);
     XtManageChild ((Widget) menuBarW);
     SetMenuBarFrame(parent);
         SetMenuBarFrame((wxFrame*) NULL);
         return FALSE;
     }
         SetMenuBarFrame((wxFrame*) NULL);
         return FALSE;
     }
     XtUnmanageChild ((Widget) m_mainWidget);
     XtUnrealizeWidget ((Widget) m_mainWidget);
     XtUnmanageChild ((Widget) m_mainWidget);
     XtUnrealizeWidget ((Widget) m_mainWidget);
     int i;
     for (i = 0; i < GetMenuCount(); i++)
     {
         wxMenu *menu = GetMenu(i);
         menu->DestroyMenu(TRUE);
     int i;
     for (i = 0; i < GetMenuCount(); i++)
     {
         wxMenu *menu = GetMenu(i);
         menu->DestroyMenu(TRUE);
     }
     XtDestroyWidget((Widget) m_mainWidget);
     m_mainWidget = (WXWidget) 0;
     }
     XtDestroyWidget((Widget) m_mainWidget);
     m_mainWidget = (WXWidget) 0;
     SetMenuBarFrame((wxFrame*) NULL);
     SetMenuBarFrame((wxFrame*) NULL);
 {
     XtRemoveWorkProc(WorkProcMenuId);
     wxMenu *menu = (wxMenu *)clientData;
 {
     XtRemoveWorkProc(WorkProcMenuId);
     wxMenu *menu = (wxMenu *)clientData;
     if (menu->GetMainWidget()) {
         if (menu->GetParent())
         {
     if (menu->GetMainWidget()) {
         if (menu->GetParent())
         {
 wxMenuPopdownCallback(Widget w, XtPointer clientData,
                       XtPointer ptr)
 {
     wxMenu *menu = (wxMenu *)clientData;
 wxMenuPopdownCallback(Widget w, XtPointer clientData,
                       XtPointer ptr)
 {
     wxMenu *menu = (wxMenu *)clientData;
     // Added by JOREL Jean-Charles <jjorel@silr.ireste.fr>
     /* Since Callbacks of MenuItems are not yet processed, we put a
     * background job which will be done when system will be idle.
     * What awful hack!! :(
     */
     // Added by JOREL Jean-Charles <jjorel@silr.ireste.fr>
     /* Since Callbacks of MenuItems are not yet processed, we put a
     * background job which will be done when system will be idle.
     * What awful hack!! :(
     */
-    
-    WorkProcMenuId = XtAppAddWorkProc( 
-        (XtAppContext) wxTheApp->GetAppContext(), 
+
+    WorkProcMenuId = XtAppAddWorkProc(
+        (XtAppContext) wxTheApp->GetAppContext(),
         (XtWorkProc) PostDeletionOfMenu,
         (XtPointer) menu );
     // Apparently not found in Motif headers
         (XtWorkProc) PostDeletionOfMenu,
         (XtPointer) menu );
     // Apparently not found in Motif headers
     Arg args[5];
     XtSetArg (args[0], XmNnumColumns, m_numColumns);
     XtSetArg (args[1], XmNpacking, XmPACK_COLUMN);
     Arg args[5];
     XtSetArg (args[0], XmNnumColumns, m_numColumns);
     XtSetArg (args[1], XmNpacking, XmPACK_COLUMN);
     if (!pullDown)
     {
         menu = XmCreatePopupMenu ((Widget) parent, "popup", args, 2);
         XtAddCallback(menu,
     if (!pullDown)
     {
         menu = XmCreatePopupMenu ((Widget) parent, "popup", args, 2);
         XtAddCallback(menu,
             (XtCallbackProc)wxMenuPopdownCallback,
             (XtPointer)this);
     }
             (XtCallbackProc)wxMenuPopdownCallback,
             (XtPointer)this);
     }
     {
         char mnem = wxFindMnemonic (title);
         wxStripMenuCodes ((char*) (const char*) title, wxBuffer);
     {
         char mnem = wxFindMnemonic (title);
         wxStripMenuCodes ((char*) (const char*) title, wxBuffer);
         menu = XmCreatePulldownMenu ((Widget) parent, "pulldown", args, 2);
         menu = XmCreatePulldownMenu ((Widget) parent, "pulldown", args, 2);
         XmString label_str = XmStringCreateSimple (wxBuffer);
         buttonWidget = XtVaCreateManagedWidget (wxBuffer,
 #if wxUSE_GADGETS
         XmString label_str = XmStringCreateSimple (wxBuffer);
         buttonWidget = XtVaCreateManagedWidget (wxBuffer,
 #if wxUSE_GADGETS
             XmNlabelString, label_str,
             XmNsubMenuId, menu,
             NULL);
             XmNlabelString, label_str,
             XmNsubMenuId, menu,
             NULL);
         if (mnem != 0)
             XtVaSetValues (buttonWidget, XmNmnemonic, mnem, NULL);
         if (mnem != 0)
             XtVaSetValues (buttonWidget, XmNmnemonic, mnem, NULL);
         XmStringFree (label_str);
     }
         XmStringFree (label_str);
     }
     m_menuWidget = (WXWidget) menu;
     m_menuWidget = (WXWidget) menu;
     m_menuBar = menuBar;
     m_topLevelMenu = topMenu;
     m_menuBar = menuBar;
     m_topLevelMenu = topMenu;
     for (wxNode * node = m_menuItems.First (); node; node = node->Next ())
     {
         wxMenuItem *item = (wxMenuItem *) node->Data ();
         item->CreateItem (menu, menuBar, topMenu);
     }
     for (wxNode * node = m_menuItems.First (); node; node = node->Next ())
     {
         wxMenuItem *item = (wxMenuItem *) node->Data ();
         item->CreateItem (menu, menuBar, topMenu);
     }
     SetBackgroundColour(m_backgroundColour);
     SetForegroundColour(m_foregroundColour);
     SetFont(m_font);
     SetBackgroundColour(m_backgroundColour);
     SetForegroundColour(m_foregroundColour);
     SetFont(m_font);
     return buttonWidget;
 }
 
 // Destroys the Motif implementation of the menu,
 // but maintains the wxWindows data structures so we can
     return buttonWidget;
 }
 
 // Destroys the Motif implementation of the menu,
 // but maintains the wxWindows data structures so we can
-// do a CreateMenu again. 
+// do a CreateMenu again.
 void wxMenu::DestroyMenu (bool full)
 {
     for (wxNode * node = m_menuItems.First (); node; node = node->Next ())
     {
         wxMenuItem *item = (wxMenuItem *) node->Data ();
         item->SetMenuBar((wxMenuBar*) NULL);
 void wxMenu::DestroyMenu (bool full)
 {
     for (wxNode * node = m_menuItems.First (); node; node = node->Next ())
     {
         wxMenuItem *item = (wxMenuItem *) node->Data ();
         item->SetMenuBar((wxMenuBar*) NULL);
     if (m_buttonWidget)
     {
         if (full)
     if (m_buttonWidget)
     {
         if (full)
             *it = (wxMenuItem*) NULL;
         return m_buttonWidget;
     }
             *it = (wxMenuItem*) NULL;
         return m_buttonWidget;
     }
     for (wxNode * node = m_menuItems.First (); node; node = node->Next ())
     {
         wxMenuItem *item = (wxMenuItem *) node->Data ();
     for (wxNode * node = m_menuItems.First (); node; node = node->Next ())
     {
         wxMenuItem *item = (wxMenuItem *) node->Data ();
                 *it = item;
             return item->GetButtonWidget();
         }
                 *it = item;
             return item->GetButtonWidget();
         }
         if (item->GetSubMenu())
         {
             WXWidget w = item->GetSubMenu()->FindMenuItem (id, it);
         if (item->GetSubMenu())
         {
             WXWidget w = item->GetSubMenu()->FindMenuItem (id, it);
     if (it)
         *it = (wxMenuItem*) NULL;
     return (WXWidget) NULL;
     if (it)
         *it = (wxMenuItem*) NULL;
     return (WXWidget) NULL;
         wxDoChangeBackgroundColour(m_menuWidget, (wxColour&) col);
     if (m_buttonWidget)
         wxDoChangeBackgroundColour(m_buttonWidget, (wxColour&) col, TRUE);
         wxDoChangeBackgroundColour(m_menuWidget, (wxColour&) col);
     if (m_buttonWidget)
         wxDoChangeBackgroundColour(m_buttonWidget, (wxColour&) col, TRUE);
     wxNode* node = m_menuItems.First();
     while (node)
     {
     wxNode* node = m_menuItems.First();
     while (node)
     {
         wxDoChangeForegroundColour(m_menuWidget, (wxColour&) col);
     if (m_buttonWidget)
         wxDoChangeForegroundColour(m_buttonWidget, (wxColour&) col);
         wxDoChangeForegroundColour(m_menuWidget, (wxColour&) col);
     if (m_buttonWidget)
         wxDoChangeForegroundColour(m_buttonWidget, (wxColour&) col);
     wxNode* node = m_menuItems.First();
     while (node)
     {
     wxNode* node = m_menuItems.First();
     while (node)
     {
 void wxMenu::ChangeFont(bool keepOriginalSize)
 {
     // lesstif 0.87 hangs when setting XmNfontList
 void wxMenu::ChangeFont(bool keepOriginalSize)
 {
     // lesstif 0.87 hangs when setting XmNfontList
     if (!m_font.Ok() || !m_menuWidget)
         return;
     if (!m_font.Ok() || !m_menuWidget)
         return;
     XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay((Widget) m_menuWidget));
     XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay((Widget) m_menuWidget));
     XtVaSetValues ((Widget) m_menuWidget,
         XmNfontList, fontList,
         NULL);
     XtVaSetValues ((Widget) m_menuWidget,
         XmNfontList, fontList,
         NULL);
 
 void wxMenuBar::SetBackgroundColour(const wxColour& col)
 {
 
 void wxMenuBar::SetBackgroundColour(const wxColour& col)
 {
     m_backgroundColour = col;
     if (m_mainWidget)
         wxDoChangeBackgroundColour(m_mainWidget, (wxColour&) col);
     m_backgroundColour = col;
     if (m_mainWidget)
         wxDoChangeBackgroundColour(m_mainWidget, (wxColour&) col);
     m_foregroundColour = col;
     if (m_mainWidget)
         wxDoChangeForegroundColour(m_mainWidget, (wxColour&) col);
     m_foregroundColour = col;
     if (m_mainWidget)
         wxDoChangeForegroundColour(m_mainWidget, (wxColour&) col);
     int i;
     for (i = 0; i < m_menuCount; i++)
         m_menus[i]->SetForegroundColour((wxColour&) col);
     int i;
     for (i = 0; i < m_menuCount; i++)
         m_menus[i]->SetForegroundColour((wxColour&) col);
 {
     m_font = font;
     ChangeFont();
 {
     m_font = font;
     ChangeFont();
     int i;
     for (i = 0; i < m_menuCount; i++)
         m_menus[i]->SetFont(font);
     int i;
     for (i = 0; i < m_menuCount; i++)
         m_menus[i]->SetFont(font);
 
 // Created:     17/09/98
 // RCS-ID:      $Id$
 // Copyright:   (c) Julian Smart
 // Created:     17/09/98
 // RCS-ID:      $Id$
 // Copyright:   (c) Julian Smart
-// Licence:    wxWindows licence
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 /*
 /////////////////////////////////////////////////////////////////////////////
 
 /*
  * in Create().  The cells are freed on the next call to Create()
  * or when the destructor is called.
  */
  * in Create().  The cells are freed on the next call to Create()
  * or when the destructor is called.
  */
 /* Wolfram Gloger <u7y22ab@sunmail.lrz-muenchen.de>
 I have implemented basic colormap support for the X11 versions of
 wxWindows, notably wxPalette::Create().  The way I did it is to
 /* Wolfram Gloger <u7y22ab@sunmail.lrz-muenchen.de>
 I have implemented basic colormap support for the X11 versions of
 wxWindows, notably wxPalette::Create().  The way I did it is to
 
 wxPaletteRefData::~wxPaletteRefData()
 {
 
 wxPaletteRefData::~wxPaletteRefData()
 {
     Display *display = (Display*) NULL;
     Display *display = (Display*) NULL;
     for (node = m_palettes.First(); node; node = next) {
         wxXPalette *c = (wxXPalette *)node->Data();
         unsigned long *pix_array = c->m_pix_array;
     for (node = m_palettes.First(); node; node = next) {
         wxXPalette *c = (wxXPalette *)node->Data();
         unsigned long *pix_array = c->m_pix_array;
         bool destroyable = c->m_destroyable;
         int pix_array_n = c->m_pix_array_n;
         display = (Display*) c->m_display;
         bool destroyable = c->m_destroyable;
         int pix_array_n = c->m_pix_array_n;
         display = (Display*) c->m_display;
         if (pix_array_n > 0)
         {
             //      XFreeColors(display, cmap, pix_array, pix_array_n, 0);
         if (pix_array_n > 0)
         {
             //      XFreeColors(display, cmap, pix_array, pix_array_n, 0);
         if (destroyable)
             XFreeColormap(display, cmap);
         if (destroyable)
             XFreeColormap(display, cmap);
         next = node->Next();
         m_palettes.DeleteNode(node);
         delete c;
         next = node->Next();
         m_palettes.DeleteNode(node);
         delete c;
 bool wxPalette::Create(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue)
 {
     UnRef();
 bool wxPalette::Create(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue)
 {
     UnRef();
     if (!n) {
         return FALSE;
     }
     if (!n) {
         return FALSE;
     }
     m_refData = new wxPaletteRefData;
     m_refData = new wxPaletteRefData;
     XColor xcol;
     Display* display = (Display*) wxGetDisplay();
     XColor xcol;
     Display* display = (Display*) wxGetDisplay();
     unsigned long *pix_array;
     Colormap cmap;
     int pix_array_n;
     unsigned long *pix_array;
     Colormap cmap;
     int pix_array_n;
     cmap = (Colormap) wxTheApp->GetMainColormap(display);
     cmap = (Colormap) wxTheApp->GetMainColormap(display);
     pix_array = new unsigned long[n];
     if (!pix_array)
         return FALSE;
     pix_array = new unsigned long[n];
     if (!pix_array)
         return FALSE;
     pix_array_n = n;
     xcol.flags = DoRed | DoGreen | DoBlue;
     for(int i = 0; i < n; i++) {
     pix_array_n = n;
     xcol.flags = DoRed | DoGreen | DoBlue;
     for(int i = 0; i < n; i++) {
         xcol.blue = (unsigned short)blue[i] << 8;
         pix_array[i] = (XAllocColor(display, cmap, &xcol) == 0) ? 0 : xcol.pixel;
     }
         xcol.blue = (unsigned short)blue[i] << 8;
         pix_array[i] = (XAllocColor(display, cmap, &xcol) == 0) ? 0 : xcol.pixel;
     }
     wxXPalette *c = new wxXPalette;
     wxXPalette *c = new wxXPalette;
     c->m_pix_array_n = pix_array_n;
     c->m_pix_array = pix_array;
     c->m_cmap = (WXColormap) cmap;
     c->m_display = (WXDisplay*) display;
     c->m_destroyable = FALSE;
     M_PALETTEDATA->m_palettes.Append(c);
     c->m_pix_array_n = pix_array_n;
     c->m_pix_array = pix_array;
     c->m_cmap = (WXColormap) cmap;
     c->m_display = (WXDisplay*) display;
     c->m_destroyable = FALSE;
     M_PALETTEDATA->m_palettes.Append(c);
 {
     if ( !m_refData )
         return FALSE;
 {
     if ( !m_refData )
         return FALSE;
 {
     if ( !m_refData )
         return FALSE;
 {
     if ( !m_refData )
         return FALSE;
     if (index < 0 || index > 255)
         return FALSE;
     if (index < 0 || index > 255)
         return FALSE;
 {
     if (!M_PALETTEDATA || (M_PALETTEDATA->m_palettes.Number() == 0))
         return wxTheApp->GetMainColormap(display);
 {
     if (!M_PALETTEDATA || (M_PALETTEDATA->m_palettes.Number() == 0))
         return wxTheApp->GetMainColormap(display);
     wxNode* node = M_PALETTEDATA->m_palettes.First();
     if (!display && node)
     {
     wxNode* node = M_PALETTEDATA->m_palettes.First();
     if (!display && node)
     {
         wxXPalette* p = (wxXPalette*) node->Data();
         if (p->m_display == display)
             return p->m_cmap;
         wxXPalette* p = (wxXPalette*) node->Data();
         if (p->m_display == display)
             return p->m_cmap;
     /* Make a new one: */
     wxXPalette *c = new wxXPalette;
     wxXPalette *first = (wxXPalette *)M_PALETTEDATA->m_palettes.First()->Data();
     XColor xcol;
     int pix_array_n = first->m_pix_array_n;
     /* Make a new one: */
     wxXPalette *c = new wxXPalette;
     wxXPalette *first = (wxXPalette *)M_PALETTEDATA->m_palettes.First()->Data();
     XColor xcol;
     int pix_array_n = first->m_pix_array_n;
     c->m_pix_array_n = pix_array_n;
     c->m_pix_array = new unsigned long[pix_array_n];
     c->m_display = display;
     c->m_cmap = wxTheApp->GetMainColormap(display);
     c->m_destroyable = FALSE;
     c->m_pix_array_n = pix_array_n;
     c->m_pix_array = new unsigned long[pix_array_n];
     c->m_display = display;
     c->m_cmap = wxTheApp->GetMainColormap(display);
     c->m_destroyable = FALSE;
     xcol.flags = DoRed | DoGreen | DoBlue;
     int i;
     for (i = 0; i < pix_array_n; i++)
     xcol.flags = DoRed | DoGreen | DoBlue;
     int i;
     for (i = 0; i < pix_array_n; i++)
         c->m_pix_array[i] =
             (XAllocColor((Display*) display, (Colormap) c->m_cmap, &xcol) == 0) ? 0 : xcol.pixel;
     }
         c->m_pix_array[i] =
             (XAllocColor((Display*) display, (Colormap) c->m_cmap, &xcol) == 0) ? 0 : xcol.pixel;
     }
     //    wxPalette* nonConstThis = (wxPalette*) this;
     //    wxPalette* nonConstThis = (wxPalette*) this;
     M_PALETTEDATA->m_palettes.Append(c);
     M_PALETTEDATA->m_palettes.Append(c);
                     *uptr = (unsigned char)pix_array[*uptr];
                 uptr++;
             }
                     *uptr = (unsigned char)pix_array[*uptr];
                 uptr++;
             }
     if (!M_PALETTEDATA)
         return (unsigned long*) 0;
     wxNode *node;
     if (!M_PALETTEDATA)
         return (unsigned long*) 0;
     wxNode *node;
     for (node = M_PALETTEDATA->m_palettes.First(); node; node = node->Next())
     {
         wxXPalette *c = (wxXPalette *)node->Data();
     for (node = M_PALETTEDATA->m_palettes.First(); node; node = node->Next())
     {
         wxXPalette *c = (wxXPalette *)node->Data();
             return c->m_pix_array;
         }
     }
             return c->m_pix_array;
         }
     }
     /* Not found; call GetXColormap, which will create it, then this again */
     if (GetXColormap(display))
         return GetXPixArray(display, n);
     /* Not found; call GetXColormap, which will create it, then this again */
     if (GetXColormap(display))
         return GetXPixArray(display, n);
 void wxPalette::PutXColormap(WXDisplay* display, WXColormap cm, bool dp)
 {
     UnRef();
 void wxPalette::PutXColormap(WXDisplay* display, WXColormap cm, bool dp)
 {
     UnRef();
     m_refData = new wxPaletteRefData;
     m_refData = new wxPaletteRefData;
     wxXPalette *c = new wxXPalette;
     wxXPalette *c = new wxXPalette;
     c->m_pix_array_n = 0;
     c->m_pix_array = (unsigned long*) NULL;
     c->m_display = display;
     c->m_cmap = cm;
     c->m_destroyable = dp;
     c->m_pix_array_n = 0;
     c->m_pix_array = (unsigned long*) NULL;
     c->m_display = display;
     c->m_cmap = cm;
     c->m_destroyable = dp;
     M_PALETTEDATA->m_palettes.Append(c);
 }
 
     M_PALETTEDATA->m_palettes.Append(c);
 }
 
 
 // Created:     04/01/98
 // RCS-ID:      $Id$
 // Copyright:   (c) Julian Smart
 // Created:     04/01/98
 // RCS-ID:      $Id$
 // Copyright:   (c) Julian Smart
-// Licence:    wxWindows licence
+// Licence:           wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 #ifdef __GNUG__
 /////////////////////////////////////////////////////////////////////////////
 
 #ifdef __GNUG__
 #endif
 
 static void wxToolButtonCallback (Widget w, XtPointer clientData,
 #endif
 
 static void wxToolButtonCallback (Widget w, XtPointer clientData,
 static void wxToolButtonPopupCallback (Widget w, XtPointer client_data,
                      XEvent *event, Boolean *continue_to_dispatch);
 
 static void wxToolButtonPopupCallback (Widget w, XtPointer client_data,
                      XEvent *event, Boolean *continue_to_dispatch);
 
 {
     m_maxWidth = -1;
     m_maxHeight = -1;
 {
     m_maxWidth = -1;
     m_maxHeight = -1;
     m_defaultWidth = 24;
     m_defaultHeight = 22;
     SetName(name);
     m_defaultWidth = 24;
     m_defaultHeight = 22;
     SetName(name);
     AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
 
     ChangeBackgroundColour();
     AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
 
     ChangeBackgroundColour();
-                button = XtVaCreateWidget("toggleButton", 
+                button = XtVaCreateWidget("toggleButton",
                    xmToggleButtonWidgetClass, (Widget) m_mainWidget,
                    XmNx, currentX, XmNy, currentY,
                    xmToggleButtonWidgetClass, (Widget) m_mainWidget,
                    XmNx, currentX, XmNy, currentY,
-                                                //                   XmNpushButtonEnabled, True,
+                                                 //                   XmNpushButtonEnabled, True,
                    XmNmultiClick, XmMULTICLICK_KEEP,
                    XmNlabelType, XmPIXMAP,
                    NULL);
                 XtAddCallback ((Widget) button, XmNvalueChangedCallback, (XtCallbackProc) wxToolButtonCallback,
                    XmNmultiClick, XmMULTICLICK_KEEP,
                    XmNlabelType, XmPIXMAP,
                    NULL);
                 XtAddCallback ((Widget) button, XmNvalueChangedCallback, (XtCallbackProc) wxToolButtonCallback,
 
                 XtVaSetValues ((Widget) button,
                       XmNselectColor, m_backgroundColour.AllocColour(XtDisplay((Widget) button)),
 
                 XtVaSetValues ((Widget) button,
                       XmNselectColor, m_backgroundColour.AllocColour(XtDisplay((Widget) button)),
-                button = XtVaCreateWidget("button", 
+                button = XtVaCreateWidget("button",
                    xmPushButtonWidgetClass, (Widget) m_mainWidget,
                    XmNx, currentX, XmNy, currentY,
                    XmNpushButtonEnabled, True,
                    xmPushButtonWidgetClass, (Widget) m_mainWidget,
                    XmNx, currentX, XmNy, currentY,
                    XmNpushButtonEnabled, True,
             {
                 int backgroundPixel;
                 XtVaGetValues(button, XmNbackground, &backgroundPixel,
             {
                 int backgroundPixel;
                 XtVaGetValues(button, XmNbackground, &backgroundPixel,
 
 
                 wxColour col;
                 col.SetPixel(backgroundPixel);
 
 
                 wxColour col;
                 col.SetPixel(backgroundPixel);
                 wxBitmap newBitmap = wxCreateMaskedBitmap(tool->m_bitmap1, col);
 
                 tool->m_bitmap1 = newBitmap;
                 wxBitmap newBitmap = wxCreateMaskedBitmap(tool->m_bitmap1, col);
 
                 tool->m_bitmap1 = newBitmap;
             int backgroundPixel;
             if (tool->m_isToggle)
                 XtVaGetValues(button, XmNselectColor, &backgroundPixel,
             int backgroundPixel;
             if (tool->m_isToggle)
                 XtVaGetValues(button, XmNselectColor, &backgroundPixel,
             else
                 XtVaGetValues(button, XmNarmColor, &backgroundPixel,
             else
                 XtVaGetValues(button, XmNarmColor, &backgroundPixel,
 
             wxColour col;
             col.SetPixel(backgroundPixel);
 
             wxColour col;
             col.SetPixel(backgroundPixel);
                 {
                     wxBitmap newBitmap = wxCreateMaskedBitmap(originalBitmap, col);
                     tool->m_bitmap2 = newBitmap;
                 {
                     wxBitmap newBitmap = wxCreateMaskedBitmap(originalBitmap, col);
                     tool->m_bitmap2 = newBitmap;
                 else
                     tool->m_bitmap2 = tool->m_bitmap1;
             }
                 else
                     tool->m_bitmap2 = tool->m_bitmap1;
             }
                 }
                 XtVaSetValues (button,
                     XmNindicatorOn, False,
                 }
                 XtVaSetValues (button,
                     XmNindicatorOn, False,
-                   XmNshadowThickness, 2,
-                              //                   XmNborderWidth, 0,
-                              //                   XmNspacing, 0,
-                   XmNmarginWidth, 0,
-                   XmNmarginHeight, 0,
+                    XmNshadowThickness, 2,
+                               //                    XmNborderWidth, 0,
+                               //                    XmNspacing, 0,
+                    XmNmarginWidth, 0,
+                    XmNmarginHeight, 0,
                     XmNfillOnSelect, True,
                     XmNlabelPixmap, pixmap,
                     XmNselectPixmap, pixmap2,
                     XmNfillOnSelect, True,
                     XmNlabelPixmap, pixmap,
                     XmNselectPixmap, pixmap2,
 
             Dimension width, height;
             XtVaGetValues(button, XmNwidth, & width, XmNheight, & height,
 
             Dimension width, height;
             XtVaGetValues(button, XmNwidth, & width, XmNheight, & height,
             currentX += width + marginX;
             buttonHeight = wxMax(buttonHeight, height);
 
             currentX += width + marginX;
             buttonHeight = wxMax(buttonHeight, height);
 
-            XtAddEventHandler (button, EnterWindowMask | LeaveWindowMask, 
+            XtAddEventHandler (button, EnterWindowMask | LeaveWindowMask,
                        False, wxToolButtonPopupCallback, (XtPointer) this);
             m_widgets.Append(tool->m_index, (wxObject*) button);
 
                        False, wxToolButtonPopupCallback, (XtPointer) this);
             m_widgets.Append(tool->m_index, (wxObject*) button);
 
 
 
 void wxToolButtonCallback (Widget w, XtPointer clientData,
 
 
 void wxToolButtonCallback (Widget w, XtPointer clientData,
 {
     wxToolBar *toolBar = (wxToolBar *) clientData;
     int index = toolBar->FindIndexForWidget((WXWidget) w);
 {
     wxToolBar *toolBar = (wxToolBar *) clientData;
     int index = toolBar->FindIndexForWidget((WXWidget) w);
         wxNode *node = toolBar->GetTools().Find((long)index);
         if (!node)
             return;
         wxNode *node = toolBar->GetTools().Find((long)index);
         if (!node)
             return;
-        wxToolBarTool *tool = (wxToolBarTool *)node->Data();
         wxString str(toolBar->GetToolShortHelp(index));
         if (str.IsNull() || str == "")
             return;
         wxString str(toolBar->GetToolShortHelp(index));
         if (str.IsNull() || str == "")
             return;
         if (!wxTheToolBarTimer)
           wxTheToolBarTimer = new wxToolBarTimer;
 
         if (!wxTheToolBarTimer)
           wxTheToolBarTimer = new wxToolBarTimer;
 
-       wxToolBarTimer::buttonWidget = w;
-       wxToolBarTimer::helpString = str;
+        wxToolBarTimer::buttonWidget = w;
+        wxToolBarTimer::helpString = str;
 
 
     /************************************************************/
 
 
     /************************************************************/
         {
             XtDestroyWidget (wxToolBarTimer::help_popup);
             XtPopdown (wxToolBarTimer::help_popup);
         {
             XtDestroyWidget (wxToolBarTimer::help_popup);
             XtPopdown (wxToolBarTimer::help_popup);
         wxToolBarTimer::help_popup = (Widget) 0;
 
         // One shot
         wxToolBarTimer::help_popup = (Widget) 0;
 
         // One shot
         {
             XtDestroyWidget (wxToolBarTimer::help_popup);
             XtPopdown (wxToolBarTimer::help_popup);
         {
             XtDestroyWidget (wxToolBarTimer::help_popup);
             XtPopdown (wxToolBarTimer::help_popup);
         wxToolBarTimer::help_popup = (Widget) 0;
     }
     }
         wxToolBarTimer::help_popup = (Widget) 0;
     }
     }
         /************************************************************/
         /* Create shell without window decorations                  */
         /************************************************************/
         /************************************************************/
         /* Create shell without window decorations                  */
         /************************************************************/
-        help_popup = XtVaCreatePopupShell ("shell", 
-                                           overrideShellWidgetClass, (Widget) wxTheApp->GetTopLevelWidget(), 
+        help_popup = XtVaCreatePopupShell ("shell",
+                                           overrideShellWidgetClass, (Widget) wxTheApp->GetTopLevelWidget(),
                                            NULL);
 
         /************************************************************/
         /* Get absolute position on display of toolbar button       */
         /************************************************************/
         XtTranslateCoords (buttonWidget,
                                            NULL);
 
         /************************************************************/
         /* Get absolute position on display of toolbar button       */
         /************************************************************/
         XtTranslateCoords (buttonWidget,
-                           (Position) 0, 
-                           (Position) 0, 
+                           (Position) 0,
+                           (Position) 0,
                            &x, &y);
 
         // Move the tooltip more or less above the button
                            &x, &y);
 
         // Move the tooltip more or less above the button
         /************************************************************/
         /* Set the position of the help popup                       */
         /************************************************************/
         /************************************************************/
         /* Set the position of the help popup                       */
         /************************************************************/
-        XtVaSetValues (help_popup, 
-                       XmNx, (Position) x, 
-                       XmNy, (Position) y, 
+        XtVaSetValues (help_popup,
+                       XmNx, (Position) x,
+                       XmNy, (Position) y,
         /************************************************************/
         /* Create help label                                        */
         /************************************************************/
         XmString text = XmStringCreateSimple ((char*) (const char*) helpString);
         /************************************************************/
         /* Create help label                                        */
         /************************************************************/
         XmString text = XmStringCreateSimple ((char*) (const char*) helpString);
-        XtVaCreateManagedWidget ("help_label", 
-                                 xmLabelWidgetClass, help_popup, 
+        XtVaCreateManagedWidget ("help_label",
+                                 xmLabelWidgetClass, help_popup,
-                                 XtVaTypedArg, 
-                                 XmNforeground, XtRString, "black", 
-                                                strlen("black")+1,      
-                                 XtVaTypedArg, 
-                                 XmNbackground, XtRString, "LightGoldenrod", 
-                                                strlen("LightGoldenrod")+1, 
+                                 XtVaTypedArg,
+                                 XmNforeground, XtRString, "black",
+                                                strlen("black")+1,
+                                 XtVaTypedArg,
+                                 XmNbackground, XtRString, "LightGoldenrod",
+                                                strlen("LightGoldenrod")+1,
                                  NULL);
         XmStringFree (text);
 
                                  NULL);
         XmStringFree (text);
 
 
     Display *display = (Display*) wxGetDisplay();
 
     XSync (display, FALSE);
     Display *display = (Display*) wxGetDisplay();
 
     XSync (display, FALSE);
     // XtAppPending returns availability of events AND timers/inputs, which
     // are processed via callbacks, so XtAppNextEvent will not return if
     // there are no events. So added '& XtIMXEvent' - Sergey.
     // XtAppPending returns availability of events AND timers/inputs, which
     // are processed via callbacks, so XtAppNextEvent will not return if
     // there are no events. So added '& XtIMXEvent' - Sergey.