From e2414cbe8c21931afbb590132232553514da824c Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Mon, 20 Jul 1998 18:05:48 +0000 Subject: [PATCH] many fixes to wxTextCrtl, wxTreeCrtl, wxListBox, wxDialog, wxFrame two more samples work now, docview and treectrl git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@316 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/generic/imaglist.h | 7 ++++ include/wx/generic/treectrl.h | 10 +++-- include/wx/gtk/dialog.h | 6 +-- include/wx/gtk/frame.h | 3 ++ include/wx/gtk/listbox.h | 1 + include/wx/gtk/menu.h | 15 +++++++ include/wx/gtk1/dialog.h | 6 +-- include/wx/gtk1/frame.h | 3 ++ include/wx/gtk1/listbox.h | 1 + include/wx/gtk1/menu.h | 15 +++++++ samples/docview/docview.cpp | 2 +- samples/treectrl/treetest.cpp | 3 ++ src/generic/treectrl.cpp | 70 ++++++++++++++++++++++++------- src/gtk/dialog.cpp | 14 ++++++- src/gtk/filedlg.cpp | 2 +- src/gtk/frame.cpp | 52 +++++++++++++++++++++++ src/gtk/listbox.cpp | 38 ++++++++++++++--- src/gtk/menu.cpp | 7 +++- src/gtk/textctrl.cpp | 78 +++-------------------------------- src/gtk1/dialog.cpp | 14 ++++++- src/gtk1/filedlg.cpp | 2 +- src/gtk1/frame.cpp | 52 +++++++++++++++++++++++ src/gtk1/listbox.cpp | 38 ++++++++++++++--- src/gtk1/menu.cpp | 7 +++- src/gtk1/textctrl.cpp | 78 +++-------------------------------- 25 files changed, 334 insertions(+), 190 deletions(-) diff --git a/include/wx/generic/imaglist.h b/include/wx/generic/imaglist.h index 2a0893a3ac..2d7248f203 100644 --- a/include/wx/generic/imaglist.h +++ b/include/wx/generic/imaglist.h @@ -40,6 +40,13 @@ #define wxIMAGELIST_DRAW_SELECTED 0x0004 #define wxIMAGELIST_DRAW_FOCUSED 0x0008 +// Flag values for Set/GetImageList +enum { + wxIMAGE_LIST_NORMAL, // Normal icons + wxIMAGE_LIST_SMALL, // Small icons + wxIMAGE_LIST_STATE // State icons: unimplemented (see WIN32 documentation) +}; + class wxImageList: public wxObject { DECLARE_DYNAMIC_CLASS(wxImageList) diff --git a/include/wx/generic/treectrl.h b/include/wx/generic/treectrl.h index 03cee90cff..a26f8ffc80 100644 --- a/include/wx/generic/treectrl.h +++ b/include/wx/generic/treectrl.h @@ -276,6 +276,9 @@ public: void DeleteItem( long item ); void DeleteChildren( long item ); bool DeleteAllItems(); + bool ExpandItem(long item) { return ExpandItem(item, wxTREE_EXPAND_EXPAND); } + bool CollapseItem(long item) { return ExpandItem(item, wxTREE_EXPAND_COLLAPSE); } + bool ToggleItem(long item) { return ExpandItem(item, wxTREE_EXPAND_TOGGLE); } bool ExpandItem( long item, int action ); bool GetItem( wxTreeItem &info ) const; long GetItemData( long item ) const; @@ -302,9 +305,9 @@ public: void OnChar( wxKeyEvent &event ); void OnMouse( const wxMouseEvent &event ); - void SetImageList(wxImageList *imageList) { m_imageList = imageList; } - wxImageList *GetImageList() const { return m_imageList; } - + wxImageList *GetImageList(int which = wxIMAGE_LIST_NORMAL) const; + void SetImageList(wxImageList *imageList, int which = wxIMAGE_LIST_NORMAL); + private: wxGenericTreeItem *m_anchor; wxGenericTreeItem *m_current; @@ -318,6 +321,7 @@ private: wxPaintDC *m_dc; wxBrush *m_hilightBrush; wxImageList *m_imageList; + wxImageList *m_smallImageList; void CalculateLevel( wxGenericTreeItem *item, wxPaintDC &dc, int level, int &y ); void CalculatePositions(); diff --git a/include/wx/gtk/dialog.h b/include/wx/gtk/dialog.h index 44f11d3fdf..db28c7772b 100644 --- a/include/wx/gtk/dialog.h +++ b/include/wx/gtk/dialog.h @@ -65,6 +65,7 @@ class wxDialog: public wxWindow void OnCancel( wxCommandEvent &event ); void OnOk( wxCommandEvent &event ); void OnPaint(wxPaintEvent& event); + bool Destroy(void); void OnCloseWindow(wxCloseEvent& event); /* void OnCharHook(wxKeyEvent& event); @@ -74,11 +75,6 @@ class wxDialog: public wxWindow virtual void EndModal(int retCode); virtual bool IsModal(void) const { return ((GetWindowStyleFlag() & wxDIALOG_MODAL) == wxDIALOG_MODAL); } virtual void InitDialog(void); -/* - void OnOK(wxCommandEvent& event); - void OnApply(wxCommandEvent& event); - void OnCancel(wxCommandEvent& event); -*/ private: diff --git a/include/wx/gtk/frame.h b/include/wx/gtk/frame.h index 517edc9506..9e909a9b5e 100644 --- a/include/wx/gtk/frame.h +++ b/include/wx/gtk/frame.h @@ -69,10 +69,13 @@ class wxFrame: public wxWindow void SetTitle( const wxString &title ); wxString GetTitle(void) const; void OnActivate( wxActivateEvent &WXUNUSED(event) ) {}; + void OnIdle( wxIdleEvent &event ); //private: void GtkOnSize( int x, int y, int width, int height ); + void DoMenuUpdates(void); + void DoMenuUpdates(wxMenu* menu); private: diff --git a/include/wx/gtk/listbox.h b/include/wx/gtk/listbox.h index 55ba995672..ee3332ba2e 100644 --- a/include/wx/gtk/listbox.h +++ b/include/wx/gtk/listbox.h @@ -76,6 +76,7 @@ class wxListBox: public wxControl private: GtkList *m_list; + wxList m_clientData; public: diff --git a/include/wx/gtk/menu.h b/include/wx/gtk/menu.h index 83376e780b..d4c48d4cd4 100644 --- a/include/wx/gtk/menu.h +++ b/include/wx/gtk/menu.h @@ -29,6 +29,12 @@ class wxMenuBar; class wxMenuItem; class wxMenu; +//----------------------------------------------------------------------------- +// const +//----------------------------------------------------------------------------- + +#define ID_SEPARATOR (-1) + //----------------------------------------------------------------------------- // wxMenuBar //----------------------------------------------------------------------------- @@ -69,6 +75,14 @@ class wxMenuItem: public wxObject wxString m_helpStr; GtkWidget *m_menuItem; // GtkMenuItem + + bool IsSeparator() const { return m_id == ID_SEPARATOR; } + bool IsEnabled() const { return m_isEnabled; } + bool IsChecked() const { return m_checked; } + + int GetId() const { return m_id; } + const wxString& GetHelp() const { return m_helpStr; } + wxMenu *GetSubMenu() const { return m_subMenu; } }; @@ -86,6 +100,7 @@ class wxMenu: public wxEvtHandler wxMenu *subMenu, const wxString &helpStr = "" ); int FindItem( const wxString itemString ) const; void Break(void) {}; + void Check(int id, bool Flag); void Enable( int id, bool enable ); bool Enabled( int id ) const; void SetLabel( int id, const wxString &label ); diff --git a/include/wx/gtk1/dialog.h b/include/wx/gtk1/dialog.h index 44f11d3fdf..db28c7772b 100644 --- a/include/wx/gtk1/dialog.h +++ b/include/wx/gtk1/dialog.h @@ -65,6 +65,7 @@ class wxDialog: public wxWindow void OnCancel( wxCommandEvent &event ); void OnOk( wxCommandEvent &event ); void OnPaint(wxPaintEvent& event); + bool Destroy(void); void OnCloseWindow(wxCloseEvent& event); /* void OnCharHook(wxKeyEvent& event); @@ -74,11 +75,6 @@ class wxDialog: public wxWindow virtual void EndModal(int retCode); virtual bool IsModal(void) const { return ((GetWindowStyleFlag() & wxDIALOG_MODAL) == wxDIALOG_MODAL); } virtual void InitDialog(void); -/* - void OnOK(wxCommandEvent& event); - void OnApply(wxCommandEvent& event); - void OnCancel(wxCommandEvent& event); -*/ private: diff --git a/include/wx/gtk1/frame.h b/include/wx/gtk1/frame.h index 517edc9506..9e909a9b5e 100644 --- a/include/wx/gtk1/frame.h +++ b/include/wx/gtk1/frame.h @@ -69,10 +69,13 @@ class wxFrame: public wxWindow void SetTitle( const wxString &title ); wxString GetTitle(void) const; void OnActivate( wxActivateEvent &WXUNUSED(event) ) {}; + void OnIdle( wxIdleEvent &event ); //private: void GtkOnSize( int x, int y, int width, int height ); + void DoMenuUpdates(void); + void DoMenuUpdates(wxMenu* menu); private: diff --git a/include/wx/gtk1/listbox.h b/include/wx/gtk1/listbox.h index 55ba995672..ee3332ba2e 100644 --- a/include/wx/gtk1/listbox.h +++ b/include/wx/gtk1/listbox.h @@ -76,6 +76,7 @@ class wxListBox: public wxControl private: GtkList *m_list; + wxList m_clientData; public: diff --git a/include/wx/gtk1/menu.h b/include/wx/gtk1/menu.h index 83376e780b..d4c48d4cd4 100644 --- a/include/wx/gtk1/menu.h +++ b/include/wx/gtk1/menu.h @@ -29,6 +29,12 @@ class wxMenuBar; class wxMenuItem; class wxMenu; +//----------------------------------------------------------------------------- +// const +//----------------------------------------------------------------------------- + +#define ID_SEPARATOR (-1) + //----------------------------------------------------------------------------- // wxMenuBar //----------------------------------------------------------------------------- @@ -69,6 +75,14 @@ class wxMenuItem: public wxObject wxString m_helpStr; GtkWidget *m_menuItem; // GtkMenuItem + + bool IsSeparator() const { return m_id == ID_SEPARATOR; } + bool IsEnabled() const { return m_isEnabled; } + bool IsChecked() const { return m_checked; } + + int GetId() const { return m_id; } + const wxString& GetHelp() const { return m_helpStr; } + wxMenu *GetSubMenu() const { return m_subMenu; } }; @@ -86,6 +100,7 @@ class wxMenu: public wxEvtHandler wxMenu *subMenu, const wxString &helpStr = "" ); int FindItem( const wxString itemString ) const; void Break(void) {}; + void Check(int id, bool Flag); void Enable( int id, bool enable ); bool Enabled( int id ) const; void SetLabel( int id, const wxString &label ); diff --git a/samples/docview/docview.cpp b/samples/docview/docview.cpp index 075238f442..8943fb94c6 100644 --- a/samples/docview/docview.cpp +++ b/samples/docview/docview.cpp @@ -126,7 +126,7 @@ bool MyApp::OnInit(void) file_menu->AppendSeparator(); file_menu->Append(wxID_EXIT, "E&xit"); - + // A nice touch: a history of files visited. Use this menu. m_docManager->FileHistoryUseMenu(file_menu); diff --git a/samples/treectrl/treetest.cpp b/samples/treectrl/treetest.cpp index f162be97ae..48759220c0 100644 --- a/samples/treectrl/treetest.cpp +++ b/samples/treectrl/treetest.cpp @@ -73,10 +73,13 @@ bool MyApp::OnInit(void) // Make an image list containing small icons m_imageListNormal = new wxImageList(16, 16, TRUE); +#ifdef __WXMSW__ wxIcon icon1("icon1", wxBITMAP_TYPE_ICO_RESOURCE); m_imageListNormal->Add(icon1); wxIcon icon2("icon2", wxBITMAP_TYPE_ICO_RESOURCE); m_imageListNormal->Add(icon2); +#else +#endif // Make a menubar wxMenu *file_menu = new wxMenu; diff --git a/src/generic/treectrl.cpp b/src/generic/treectrl.cpp index 91f7733f4f..a24f76cde2 100644 --- a/src/generic/treectrl.cpp +++ b/src/generic/treectrl.cpp @@ -236,13 +236,16 @@ long wxGenericTreeItem::HitTest( const wxPoint& point, int &flags ) } else { - wxNode *node = m_children.First(); - while (node) + if (!m_isCollapsed) { - wxGenericTreeItem *child = (wxGenericTreeItem*)node->Data(); - long res = child->HitTest( point, flags ); - if (res != -1) return res; - node = node->Next(); + wxNode *node = m_children.First(); + while (node) + { + wxGenericTreeItem *child = (wxGenericTreeItem*)node->Data(); + long res = child->HitTest( point, flags ); + if (res != -1) return res; + node = node->Next(); + }; }; }; return -1; @@ -352,6 +355,8 @@ wxTreeCtrl::wxTreeCtrl() m_isCreated = FALSE; m_dc = NULL; m_hilightBrush = new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT), wxSOLID ); + m_imageList = NULL; + m_smallImageList = NULL; }; wxTreeCtrl::wxTreeCtrl(wxWindow *parent, wxWindowID id, @@ -369,6 +374,8 @@ wxTreeCtrl::wxTreeCtrl(wxWindow *parent, wxWindowID id, m_isCreated = FALSE; m_dc = NULL; m_hilightBrush = new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT), wxSOLID ); + m_imageList = NULL; + m_smallImageList = NULL; Create( parent, id, pos, size, style, name ); }; @@ -437,6 +444,8 @@ long wxTreeCtrl::InsertItem( long parent, const wxString& label, int image, { CalculatePositions(); + if (!p->HasChildren()) p->m_hasChildren = TRUE; + int ch = 0; GetClientSize( NULL, &ch ); @@ -515,6 +524,8 @@ long wxTreeCtrl::InsertItem( long parent, wxTreeItem &info, long WXUNUSED(insert if (p) { CalculatePositions(); + + if (!p->HasChildren()) p->m_hasChildren = TRUE; int ch = 0; GetClientSize( NULL, &ch ); @@ -581,6 +592,8 @@ bool wxTreeCtrl::ExpandItem( long item, int action ) node = node->Next(); }; + CalculatePositions(); + i->SendCollapse( this ); break; } @@ -757,6 +770,26 @@ long wxTreeCtrl::HitTest( const wxPoint& point, int &flags ) return m_anchor->HitTest( point, flags ); }; +wxImageList *wxTreeCtrl::GetImageList( int which ) const +{ + if (which == wxIMAGE_LIST_NORMAL) return m_imageList; + return m_smallImageList; +}; + +void wxTreeCtrl::SetImageList( wxImageList *imageList, int which ) +{ + if (which == wxIMAGE_LIST_NORMAL) + { + if (m_imageList) delete m_imageList; + m_imageList = imageList; + } + else + { + if (m_smallImageList) delete m_smallImageList; + m_smallImageList = imageList; + }; +}; + void wxTreeCtrl::AdjustMyScrollbars() { if (m_anchor) @@ -810,13 +843,18 @@ void wxTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxPaintDC &dc, int level, { dc.SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT ) ); dc.SetBrush( *m_hilightBrush ); - if (m_hasFocus) - dc.SetPen( *wxBLACK_PEN ); - else - dc.SetPen( *wxWHITE_PEN ); long tw, th; dc.GetTextExtent( item->m_text, &tw, &th ); - dc.DrawRectangle( item->m_x-2, item->m_y-2, tw+4, th+4 ); + if (m_hasFocus) + { + dc.SetPen( *wxBLACK_PEN ); + dc.DrawRectangle( item->m_x-2, item->m_y-2, tw+4, th+4 ); + } + else + { + dc.SetPen( *wxTRANSPARENT_PEN ); + dc.DrawRectangle( item->m_x-2, item->m_y-2, tw+4, th+4 ); + } dc.DrawText( item->m_text, item->m_x, item->m_y ); dc.SetPen( *wxBLACK_PEN ); @@ -825,7 +863,7 @@ void wxTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxPaintDC &dc, int level, } else { - dc.SetPen( *wxWHITE_PEN ); + dc.SetPen( *wxTRANSPARENT_PEN ); long tw, th; dc.GetTextExtent( item->m_text, &tw, &th ); dc.DrawRectangle( item->m_x-2, item->m_y-2, tw+4, th+4 ); @@ -835,19 +873,23 @@ void wxTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxPaintDC &dc, int level, }; if (item->NumberOfVisibleChildren() == 0) return; - + + int semiOldY = y; + wxNode *node = item->m_children.First(); while (node) { wxGenericTreeItem *child = (wxGenericTreeItem *)node->Data(); y += m_lineHeight; + semiOldY = y; + PaintLevel( child, dc, level+1, y ); node = node->Next(); }; - dc.DrawLine( horizX+15, oldY+5, horizX+15, y ); + dc.DrawLine( horizX+15, oldY+5, horizX+15, semiOldY ); } void wxTreeCtrl::OnPaint( const wxPaintEvent &WXUNUSED(event) ) diff --git a/src/gtk/dialog.cpp b/src/gtk/dialog.cpp index b38fedf806..f472f31e6c 100644 --- a/src/gtk/dialog.cpp +++ b/src/gtk/dialog.cpp @@ -17,6 +17,10 @@ #include "wx/app.h" #include "wx/gtk/win_gtk.h" +//----------------------------------------------------------------------------- + +extern wxList wxPendingDelete; + //----------------------------------------------------------------------------- // delete @@ -167,6 +171,14 @@ bool wxDialog::OnClose(void) return FALSE; } +bool wxDialog::Destroy(void) +{ + if (!wxPendingDelete.Member(this)) + wxPendingDelete.Append(this); + + return TRUE; +} + void wxDialog::OnCloseWindow(wxCloseEvent& event) { if (GetEventHandler()->OnClose() || event.GetForce()) @@ -204,8 +216,8 @@ int wxDialog::ShowModal(void) void wxDialog::EndModal( int retCode ) { - gtk_main_quit(); SetReturnCode( retCode ); + gtk_main_quit(); }; void wxDialog::InitDialog(void) diff --git a/src/gtk/filedlg.cpp b/src/gtk/filedlg.cpp index 8f7b97ed89..aa05bdac13 100644 --- a/src/gtk/filedlg.cpp +++ b/src/gtk/filedlg.cpp @@ -51,7 +51,7 @@ wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message, { m_needParent = FALSE; - PreCreation( parent, -1, pos, wxDefaultSize, style, "filedialog" ); + PreCreation( parent, -1, pos, wxDefaultSize, style | wxDIALOG_MODAL, "filedialog" ); m_message = message; m_path = ""; m_fileName = defaultFileName; diff --git a/src/gtk/frame.cpp b/src/gtk/frame.cpp index c0631c4fce..aecc4ffd00 100644 --- a/src/gtk/frame.cpp +++ b/src/gtk/frame.cpp @@ -67,6 +67,7 @@ bool gtk_frame_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED( BEGIN_EVENT_TABLE(wxFrame, wxWindow) EVT_CLOSE(wxFrame::OnCloseWindow) EVT_SIZE(wxFrame::OnSize) + EVT_IDLE(wxFrame::OnIdle) END_EVENT_TABLE() IMPLEMENT_DYNAMIC_CLASS(wxFrame,wxWindow) @@ -360,3 +361,54 @@ wxString wxFrame::GetTitle(void) const return (wxString&)m_title; }; +void wxFrame::OnIdle(wxIdleEvent& WXUNUSED(event)) +{ + DoMenuUpdates(); +} + +// Query app for menu item updates (called from OnIdle) +void wxFrame::DoMenuUpdates(void) +{ + wxMenuBar* bar = GetMenuBar(); + if (!bar) return; + + wxNode *node = bar->m_menus.First(); + while (node) + { + wxMenu* menu = (wxMenu*)node->Data(); + DoMenuUpdates(menu); + + node = node->Next(); + }; +} + +void wxFrame::DoMenuUpdates(wxMenu* menu) +{ + wxNode* node = menu->m_items.First(); + while (node) + { + wxMenuItem* item = (wxMenuItem*) node->Data(); + if ( !item->IsSeparator() ) + { + wxWindowID id = item->GetId(); + wxUpdateUIEvent event(id); + event.SetEventObject( this ); + + if (GetEventHandler()->ProcessEvent(event)) + { + if (event.GetSetText()) + menu->SetLabel(id, event.GetText()); + if (event.GetSetChecked()) + menu->Check(id, event.GetChecked()); + if (event.GetSetEnabled()) + menu->Enable(id, event.GetEnabled()); + } + + if (item->GetSubMenu()) + DoMenuUpdates(item->GetSubMenu()); + } + node = node->Next(); + } +} + + diff --git a/src/gtk/listbox.cpp b/src/gtk/listbox.cpp index 58842aa9c5..aca4762937 100644 --- a/src/gtk/listbox.cpp +++ b/src/gtk/listbox.cpp @@ -92,6 +92,8 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id, gtk_container_add( GTK_CONTAINER(m_list), list_item ); + m_clientData.Append( (wxObject*)NULL ); + gtk_widget_show( list_item ); }; @@ -112,22 +114,44 @@ void wxListBox::Append( const wxString &item ) gtk_container_add( GTK_CONTAINER(m_list), list_item ); + m_clientData.Append( (wxObject*)NULL ); + gtk_widget_show( list_item ); }; -void wxListBox::Append( const wxString &WXUNUSED(item), char *WXUNUSED(clientData) ) +void wxListBox::Append( const wxString &item, char *clientData ) { - wxFAIL_MSG("wxListBox::Append(clientdata) not implemented"); + GtkWidget *list_item; + list_item = gtk_list_item_new_with_label( item ); + + gtk_signal_connect( GTK_OBJECT(list_item), "select", + GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this ); + + gtk_container_add( GTK_CONTAINER(m_list), list_item ); + + m_clientData.Append( (wxObject*)clientData ); + + gtk_widget_show( list_item ); }; void wxListBox::Clear(void) { gtk_list_clear_items( m_list, 0, Number() ); + + m_clientData.Clear(); }; void wxListBox::Delete( int n ) { gtk_list_clear_items( m_list, n, n ); + + wxNode *node = m_clientData.Nth( n ); + if (!node) + { + wxFAIL_MSG("wxListBox::Delete wrong index"); + } + else + m_clientData.DeleteNode( node ); }; void wxListBox::Deselect( int n ) @@ -150,10 +174,10 @@ int wxListBox::FindString( const wxString &item ) const return -1; }; -char *wxListBox::GetClientData( int WXUNUSED(n) ) const +char *wxListBox::GetClientData( int n ) const { - wxFAIL_MSG("wxListBox::GetClientData not implemented"); - + wxNode *node = m_clientData.Nth( n ); + if (node) return ((char*)node->Data()); return NULL; }; @@ -250,8 +274,10 @@ void wxListBox::Set( int WXUNUSED(n), const wxString *WXUNUSED(choices) ) { }; -void wxListBox::SetClientData( int WXUNUSED(n), char *WXUNUSED(clientData) ) +void wxListBox::SetClientData( int n, char *clientData ) { + wxNode *node = m_clientData.Nth( n ); + if (node) node->SetData( (wxObject*)clientData ); }; void wxListBox::SetFirstItem( int WXUNUSED(n) ) diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index 6df21c5987..3e3377f106 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -137,7 +137,7 @@ wxMenu::wxMenu( const wxString &title ) void wxMenu::AppendSeparator(void) { wxMenuItem *mitem = new wxMenuItem(); - mitem->m_id = -1; + mitem->m_id = ID_SEPARATOR; mitem->m_text = ""; mitem->m_helpStr = ""; mitem->m_isCheckMenu = FALSE; @@ -219,6 +219,11 @@ int wxMenu::FindItem( const wxString itemString ) const return -1; }; +void wxMenu::Check( int WXUNUSED(id), bool WXUNUSED(Flag) ) +{ + // I'm just too lazy +}; + void wxMenu::Enable( int id, bool enable ) { wxNode *node = m_items.First(); diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 86eef711a7..568d0babb5 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -33,6 +33,9 @@ END_EVENT_TABLE() wxTextCtrl::wxTextCtrl(void) : streambuf() { + if( allocate() ) + setp(base(),ebuf()); + m_modified = FALSE; }; @@ -40,6 +43,9 @@ wxTextCtrl::wxTextCtrl( wxWindow *parent, wxWindowID id, const wxString &value, const wxPoint &pos, const wxSize &size, int style, const wxString &name ) : streambuf() { + if( allocate() ) + setp(base(),ebuf()); + m_modified = FALSE; Create( parent, id, value, pos, size, style, name ); }; @@ -273,65 +279,6 @@ void wxTextCtrl::OnChar( wxKeyEvent &WXUNUSED(event) ) int wxTextCtrl::overflow(int c) { - // Make sure there is a holding area - if ( allocate()==EOF ) - { - wxError("Streambuf allocation failed","Internal error"); - return EOF; - } - - // Verify that there are no characters in get area - if ( gptr() && gptr() < egptr() ) - { - wxError("Who's trespassing my get area?","Internal error"); - return EOF; - } - - // Reset get area - setg(0,0,0); - - // Make sure there is a put area - if ( ! pptr() ) - { -/* This doesn't seem to be fatal so comment out error message */ -// wxError("Put area not opened","Internal error"); - setp( base(), base() ); - } - - // Determine how many characters have been inserted but no consumed - int plen = pptr() - pbase(); - - // Now Jerry relies on the fact that the buffer is at least 2 chars - // long, but the holding area "may be as small as 1" ??? - // And we need an additional \0, so let's keep this inefficient but - // safe copy. - - // If c!=EOF, it is a character that must also be comsumed - int xtra = c==EOF? 0 : 1; - - // Write temporary C-string to wxTextWindow - { - char *txt = new char[plen+xtra+1]; - memcpy(txt, pbase(), plen); - txt[plen] = (char)c; // append c - txt[plen+xtra] = '\0'; // append '\0' or overwrite c - // If the put area already contained \0, output will be truncated there - WriteText(txt); - delete[] txt; - } - - // Reset put area - setp(pbase(), epptr()); - -#if defined(__WATCOMC__) - return __NOT_EOF; -#elif defined(zapeof) // HP-UX (all cfront based?) - return zapeof(c); -#else - return c!=EOF ? c : 0; // this should make everybody happy -#endif - -/* OLD CODE int len = pptr() - pbase(); char *txt = new char[len+1]; strncpy(txt, pbase(), len); @@ -340,22 +287,10 @@ int wxTextCtrl::overflow(int c) setp(pbase(), epptr()); delete[] txt; return EOF; -*/ }; int wxTextCtrl::sync(void) { - // Verify that there are no characters in get area - if ( gptr() && gptr() < egptr() ) - { - wxError("Who's trespassing my get area?","Internal error"); - return EOF; - } - - if ( pptr() && pptr() > pbase() ) return overflow(EOF); - - return 0; -/* OLD CODE int len = pptr() - pbase(); char *txt = new char[len+1]; strncpy(txt, pbase(), len); @@ -364,7 +299,6 @@ int wxTextCtrl::sync(void) setp(pbase(), epptr()); delete[] txt; return 0; -*/ }; int wxTextCtrl::underflow(void) diff --git a/src/gtk1/dialog.cpp b/src/gtk1/dialog.cpp index b38fedf806..f472f31e6c 100644 --- a/src/gtk1/dialog.cpp +++ b/src/gtk1/dialog.cpp @@ -17,6 +17,10 @@ #include "wx/app.h" #include "wx/gtk/win_gtk.h" +//----------------------------------------------------------------------------- + +extern wxList wxPendingDelete; + //----------------------------------------------------------------------------- // delete @@ -167,6 +171,14 @@ bool wxDialog::OnClose(void) return FALSE; } +bool wxDialog::Destroy(void) +{ + if (!wxPendingDelete.Member(this)) + wxPendingDelete.Append(this); + + return TRUE; +} + void wxDialog::OnCloseWindow(wxCloseEvent& event) { if (GetEventHandler()->OnClose() || event.GetForce()) @@ -204,8 +216,8 @@ int wxDialog::ShowModal(void) void wxDialog::EndModal( int retCode ) { - gtk_main_quit(); SetReturnCode( retCode ); + gtk_main_quit(); }; void wxDialog::InitDialog(void) diff --git a/src/gtk1/filedlg.cpp b/src/gtk1/filedlg.cpp index 8f7b97ed89..aa05bdac13 100644 --- a/src/gtk1/filedlg.cpp +++ b/src/gtk1/filedlg.cpp @@ -51,7 +51,7 @@ wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message, { m_needParent = FALSE; - PreCreation( parent, -1, pos, wxDefaultSize, style, "filedialog" ); + PreCreation( parent, -1, pos, wxDefaultSize, style | wxDIALOG_MODAL, "filedialog" ); m_message = message; m_path = ""; m_fileName = defaultFileName; diff --git a/src/gtk1/frame.cpp b/src/gtk1/frame.cpp index c0631c4fce..aecc4ffd00 100644 --- a/src/gtk1/frame.cpp +++ b/src/gtk1/frame.cpp @@ -67,6 +67,7 @@ bool gtk_frame_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED( BEGIN_EVENT_TABLE(wxFrame, wxWindow) EVT_CLOSE(wxFrame::OnCloseWindow) EVT_SIZE(wxFrame::OnSize) + EVT_IDLE(wxFrame::OnIdle) END_EVENT_TABLE() IMPLEMENT_DYNAMIC_CLASS(wxFrame,wxWindow) @@ -360,3 +361,54 @@ wxString wxFrame::GetTitle(void) const return (wxString&)m_title; }; +void wxFrame::OnIdle(wxIdleEvent& WXUNUSED(event)) +{ + DoMenuUpdates(); +} + +// Query app for menu item updates (called from OnIdle) +void wxFrame::DoMenuUpdates(void) +{ + wxMenuBar* bar = GetMenuBar(); + if (!bar) return; + + wxNode *node = bar->m_menus.First(); + while (node) + { + wxMenu* menu = (wxMenu*)node->Data(); + DoMenuUpdates(menu); + + node = node->Next(); + }; +} + +void wxFrame::DoMenuUpdates(wxMenu* menu) +{ + wxNode* node = menu->m_items.First(); + while (node) + { + wxMenuItem* item = (wxMenuItem*) node->Data(); + if ( !item->IsSeparator() ) + { + wxWindowID id = item->GetId(); + wxUpdateUIEvent event(id); + event.SetEventObject( this ); + + if (GetEventHandler()->ProcessEvent(event)) + { + if (event.GetSetText()) + menu->SetLabel(id, event.GetText()); + if (event.GetSetChecked()) + menu->Check(id, event.GetChecked()); + if (event.GetSetEnabled()) + menu->Enable(id, event.GetEnabled()); + } + + if (item->GetSubMenu()) + DoMenuUpdates(item->GetSubMenu()); + } + node = node->Next(); + } +} + + diff --git a/src/gtk1/listbox.cpp b/src/gtk1/listbox.cpp index 58842aa9c5..aca4762937 100644 --- a/src/gtk1/listbox.cpp +++ b/src/gtk1/listbox.cpp @@ -92,6 +92,8 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id, gtk_container_add( GTK_CONTAINER(m_list), list_item ); + m_clientData.Append( (wxObject*)NULL ); + gtk_widget_show( list_item ); }; @@ -112,22 +114,44 @@ void wxListBox::Append( const wxString &item ) gtk_container_add( GTK_CONTAINER(m_list), list_item ); + m_clientData.Append( (wxObject*)NULL ); + gtk_widget_show( list_item ); }; -void wxListBox::Append( const wxString &WXUNUSED(item), char *WXUNUSED(clientData) ) +void wxListBox::Append( const wxString &item, char *clientData ) { - wxFAIL_MSG("wxListBox::Append(clientdata) not implemented"); + GtkWidget *list_item; + list_item = gtk_list_item_new_with_label( item ); + + gtk_signal_connect( GTK_OBJECT(list_item), "select", + GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this ); + + gtk_container_add( GTK_CONTAINER(m_list), list_item ); + + m_clientData.Append( (wxObject*)clientData ); + + gtk_widget_show( list_item ); }; void wxListBox::Clear(void) { gtk_list_clear_items( m_list, 0, Number() ); + + m_clientData.Clear(); }; void wxListBox::Delete( int n ) { gtk_list_clear_items( m_list, n, n ); + + wxNode *node = m_clientData.Nth( n ); + if (!node) + { + wxFAIL_MSG("wxListBox::Delete wrong index"); + } + else + m_clientData.DeleteNode( node ); }; void wxListBox::Deselect( int n ) @@ -150,10 +174,10 @@ int wxListBox::FindString( const wxString &item ) const return -1; }; -char *wxListBox::GetClientData( int WXUNUSED(n) ) const +char *wxListBox::GetClientData( int n ) const { - wxFAIL_MSG("wxListBox::GetClientData not implemented"); - + wxNode *node = m_clientData.Nth( n ); + if (node) return ((char*)node->Data()); return NULL; }; @@ -250,8 +274,10 @@ void wxListBox::Set( int WXUNUSED(n), const wxString *WXUNUSED(choices) ) { }; -void wxListBox::SetClientData( int WXUNUSED(n), char *WXUNUSED(clientData) ) +void wxListBox::SetClientData( int n, char *clientData ) { + wxNode *node = m_clientData.Nth( n ); + if (node) node->SetData( (wxObject*)clientData ); }; void wxListBox::SetFirstItem( int WXUNUSED(n) ) diff --git a/src/gtk1/menu.cpp b/src/gtk1/menu.cpp index 6df21c5987..3e3377f106 100644 --- a/src/gtk1/menu.cpp +++ b/src/gtk1/menu.cpp @@ -137,7 +137,7 @@ wxMenu::wxMenu( const wxString &title ) void wxMenu::AppendSeparator(void) { wxMenuItem *mitem = new wxMenuItem(); - mitem->m_id = -1; + mitem->m_id = ID_SEPARATOR; mitem->m_text = ""; mitem->m_helpStr = ""; mitem->m_isCheckMenu = FALSE; @@ -219,6 +219,11 @@ int wxMenu::FindItem( const wxString itemString ) const return -1; }; +void wxMenu::Check( int WXUNUSED(id), bool WXUNUSED(Flag) ) +{ + // I'm just too lazy +}; + void wxMenu::Enable( int id, bool enable ) { wxNode *node = m_items.First(); diff --git a/src/gtk1/textctrl.cpp b/src/gtk1/textctrl.cpp index 86eef711a7..568d0babb5 100644 --- a/src/gtk1/textctrl.cpp +++ b/src/gtk1/textctrl.cpp @@ -33,6 +33,9 @@ END_EVENT_TABLE() wxTextCtrl::wxTextCtrl(void) : streambuf() { + if( allocate() ) + setp(base(),ebuf()); + m_modified = FALSE; }; @@ -40,6 +43,9 @@ wxTextCtrl::wxTextCtrl( wxWindow *parent, wxWindowID id, const wxString &value, const wxPoint &pos, const wxSize &size, int style, const wxString &name ) : streambuf() { + if( allocate() ) + setp(base(),ebuf()); + m_modified = FALSE; Create( parent, id, value, pos, size, style, name ); }; @@ -273,65 +279,6 @@ void wxTextCtrl::OnChar( wxKeyEvent &WXUNUSED(event) ) int wxTextCtrl::overflow(int c) { - // Make sure there is a holding area - if ( allocate()==EOF ) - { - wxError("Streambuf allocation failed","Internal error"); - return EOF; - } - - // Verify that there are no characters in get area - if ( gptr() && gptr() < egptr() ) - { - wxError("Who's trespassing my get area?","Internal error"); - return EOF; - } - - // Reset get area - setg(0,0,0); - - // Make sure there is a put area - if ( ! pptr() ) - { -/* This doesn't seem to be fatal so comment out error message */ -// wxError("Put area not opened","Internal error"); - setp( base(), base() ); - } - - // Determine how many characters have been inserted but no consumed - int plen = pptr() - pbase(); - - // Now Jerry relies on the fact that the buffer is at least 2 chars - // long, but the holding area "may be as small as 1" ??? - // And we need an additional \0, so let's keep this inefficient but - // safe copy. - - // If c!=EOF, it is a character that must also be comsumed - int xtra = c==EOF? 0 : 1; - - // Write temporary C-string to wxTextWindow - { - char *txt = new char[plen+xtra+1]; - memcpy(txt, pbase(), plen); - txt[plen] = (char)c; // append c - txt[plen+xtra] = '\0'; // append '\0' or overwrite c - // If the put area already contained \0, output will be truncated there - WriteText(txt); - delete[] txt; - } - - // Reset put area - setp(pbase(), epptr()); - -#if defined(__WATCOMC__) - return __NOT_EOF; -#elif defined(zapeof) // HP-UX (all cfront based?) - return zapeof(c); -#else - return c!=EOF ? c : 0; // this should make everybody happy -#endif - -/* OLD CODE int len = pptr() - pbase(); char *txt = new char[len+1]; strncpy(txt, pbase(), len); @@ -340,22 +287,10 @@ int wxTextCtrl::overflow(int c) setp(pbase(), epptr()); delete[] txt; return EOF; -*/ }; int wxTextCtrl::sync(void) { - // Verify that there are no characters in get area - if ( gptr() && gptr() < egptr() ) - { - wxError("Who's trespassing my get area?","Internal error"); - return EOF; - } - - if ( pptr() && pptr() > pbase() ) return overflow(EOF); - - return 0; -/* OLD CODE int len = pptr() - pbase(); char *txt = new char[len+1]; strncpy(txt, pbase(), len); @@ -364,7 +299,6 @@ int wxTextCtrl::sync(void) setp(pbase(), epptr()); delete[] txt; return 0; -*/ }; int wxTextCtrl::underflow(void) -- 2.45.2