From bf9e3e736771b247eb38ada221266733b6a601c7 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Sun, 14 Nov 1999 15:14:23 +0000 Subject: [PATCH] Added wxWakeUpIdle() to wxGTK, Changed wxFindFile to detect hidden files (but not "." and ".." as before), Added "show hidden files" to file dialog, Added controls to wxToolBar, doc view now uses pretty file dialogs as per MSW. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4553 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/app.h | 5 +++++ include/wx/generic/filedlgg.h | 1 + include/wx/gtk/tbargtk.h | 16 +++++++++++----- include/wx/gtk1/tbargtk.h | 16 +++++++++++----- samples/toolbar/test.cpp | 9 +++------ src/common/docview.cpp | 6 +++--- src/common/event.cpp | 5 +---- src/common/filefn.cpp | 4 +++- src/generic/filedlgg.cpp | 10 ++++++++++ src/gtk/app.cpp | 29 +++++++++++++++++++++++------ src/gtk/bmpbuttn.cpp | 3 ++- src/gtk/tbargtk.cpp | 43 ++++++++++++++++++++++++++++++++++++++----- src/gtk1/app.cpp | 29 +++++++++++++++++++++++------ src/gtk1/bmpbuttn.cpp | 3 ++- src/gtk1/tbargtk.cpp | 43 ++++++++++++++++++++++++++++++++++++++----- 15 files changed, 174 insertions(+), 48 deletions(-) diff --git a/include/wx/app.h b/include/wx/app.h index b3715a2..cad0b66 100644 --- a/include/wx/app.h +++ b/include/wx/app.h @@ -310,6 +310,11 @@ extern void WXDLLEXPORT wxExit(); // Yield to other apps/messages extern bool WXDLLEXPORT wxYield(); +#ifdef __WXGTK__ +// Yield to other apps/messages +extern void WXDLLEXPORT wxWakeUpIdle(); +#endif + // Post a message to the given eventhandler which will be processed during the // next event loop iteration inline void WXDLLEXPORT wxPostEvent(wxEvtHandler *dest, wxEvent& event) diff --git a/include/wx/generic/filedlgg.h b/include/wx/generic/filedlgg.h index 6724c6b..59f717d 100644 --- a/include/wx/generic/filedlgg.h +++ b/include/wx/generic/filedlgg.h @@ -166,6 +166,7 @@ public: void OnNew( wxCommandEvent &event ); void OnChoice( wxCommandEvent &event ); void OnTextEnter( wxCommandEvent &event ); + void OnCheck( wxCommandEvent &event ); void HandleAction( const wxString &fn ); diff --git a/include/wx/gtk/tbargtk.h b/include/wx/gtk/tbargtk.h index 5c59c38..beb2e04 100644 --- a/include/wx/gtk/tbargtk.h +++ b/include/wx/gtk/tbargtk.h @@ -49,11 +49,11 @@ extern const wxChar *wxToolBarNameStr; class wxToolBar: public wxControl { public: - wxToolBar(void); + wxToolBar(); wxToolBar( wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = wxToolBarNameStr ); - ~wxToolBar(void); + ~wxToolBar(); bool Create( wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, @@ -76,10 +76,16 @@ public: const wxBitmap& pushedBitmap = wxNullBitmap, bool toggle = FALSE, wxCoord xPos = -1, wxCoord yPos = -1, wxObject *clientData = (wxObject *)NULL, const wxString& helpString1 = "", const wxString& helpString2 = ""); - virtual void AddSeparator(void); - virtual void ClearTools(void); - virtual bool Realize(void); + // Add arbitrary control + virtual bool AddControl(wxControl *control); + + // Add space + virtual void AddSeparator(); + + virtual void ClearTools(); + + virtual bool Realize(); virtual void EnableTool(int toolIndex, bool enable); virtual void ToggleTool(int toolIndex, bool toggle); // toggle is TRUE if toggled on diff --git a/include/wx/gtk1/tbargtk.h b/include/wx/gtk1/tbargtk.h index 5c59c38..beb2e04 100644 --- a/include/wx/gtk1/tbargtk.h +++ b/include/wx/gtk1/tbargtk.h @@ -49,11 +49,11 @@ extern const wxChar *wxToolBarNameStr; class wxToolBar: public wxControl { public: - wxToolBar(void); + wxToolBar(); wxToolBar( wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = wxToolBarNameStr ); - ~wxToolBar(void); + ~wxToolBar(); bool Create( wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, @@ -76,10 +76,16 @@ public: const wxBitmap& pushedBitmap = wxNullBitmap, bool toggle = FALSE, wxCoord xPos = -1, wxCoord yPos = -1, wxObject *clientData = (wxObject *)NULL, const wxString& helpString1 = "", const wxString& helpString2 = ""); - virtual void AddSeparator(void); - virtual void ClearTools(void); - virtual bool Realize(void); + // Add arbitrary control + virtual bool AddControl(wxControl *control); + + // Add space + virtual void AddSeparator(); + + virtual void ClearTools(); + + virtual bool Realize(); virtual void EnableTool(int toolIndex, bool enable); virtual void ToggleTool(int toolIndex, bool toggle); // toggle is TRUE if toggled on diff --git a/samples/toolbar/test.cpp b/samples/toolbar/test.cpp index 03ca8fa..f6278e4 100644 --- a/samples/toolbar/test.cpp +++ b/samples/toolbar/test.cpp @@ -224,6 +224,8 @@ bool MyApp::InitToolbar(wxToolBar* toolBar, bool smallicons) combo->Append("toolbar"); toolBar->AddControl(combo); + toolBar->AddSeparator(); + if ( !smallicons ) { currentX += width + 5; @@ -238,11 +240,6 @@ bool MyApp::InitToolbar(wxToolBar* toolBar, bool smallicons) currentX += width + 5; toolBar->AddSeparator(); toolBar->AddTool(wxID_HELP, *(toolBarBitmaps[7]), wxNullBitmap, TRUE, currentX, -1, (wxObject *) NULL, "Help button"); - - toolBar->ToggleTool( wxID_SAVE, TRUE ); - toolBar->ToggleTool( wxID_COPY, TRUE ); - toolBar->ToggleTool( wxID_COPY, FALSE ); - toolBar->EnableTool( wxID_PRINT, FALSE ); } toolBar->Realize(); @@ -303,7 +300,7 @@ MyFrame::MyFrame(wxFrame* parent, wxTB_FLAT | wxTB_DOCKABLE, ID_TOOLBAR); - tbar->SetMargins( 2, 2 ); + tbar->SetMargins( 4, 4 ); wxGetApp().InitToolbar(tbar); } diff --git a/src/common/docview.cpp b/src/common/docview.cpp index 3d582f8..a2863a4 100644 --- a/src/common/docview.cpp +++ b/src/common/docview.cpp @@ -1191,7 +1191,7 @@ wxDocTemplate *wxDocManager::FindTemplateForPath(const wxString& path) // template extension. wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates, -#ifdef __WXMSW__ +#if defined(__WXMSW__) || defined(__WXGTK__) int noTemplates, #else int WXUNUSED(noTemplates), @@ -1200,8 +1200,8 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates, long WXUNUSED(flags), bool WXUNUSED(save)) { - // We can only have multiple filters in Windows -#ifdef __WXMSW__ + // We can only have multiple filters in Windows and GTK +#if defined(__WXMSW__) || defined(__WXGTK__) wxString descrBuf; int i; diff --git a/src/common/event.cpp b/src/common/event.cpp index 1b71ae0..13a9a70 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -611,10 +611,7 @@ void wxEvtHandler::AddPendingEvent(wxEvent& event) // TODO: Wake up idle handler for the other platforms. #ifdef __WXGTK__ - extern bool g_isIdle; - extern void wxapp_install_idle_handler(); - if ( g_isIdle ) - wxapp_install_idle_handler(); + wxWakeUpIdle(); #elif wxUSE_GUI // this works for wxMSW, but may be for others too? // might also send a dummy message to the top level window, this would // probably be cleaner? diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index f4a1e78..88d201f 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -1304,7 +1304,9 @@ wxString wxFindNextFile() nextDir != NULL; nextDir = readdir(gs_dirStream) ) { - if (wxMatchWild(name, nextDir->d_name)) + if (wxMatchWild(name, nextDir->d_name, FALSE) && // RR: added FALSE to find hidden files + strcmp(nextDir->d_name, ".") && + strcmp(nextDir->d_name, "..") ) { result.Empty(); if ( !path.IsEmpty() ) diff --git a/src/generic/filedlgg.cpp b/src/generic/filedlgg.cpp index 87b1f4f..9f1eaee 100644 --- a/src/generic/filedlgg.cpp +++ b/src/generic/filedlgg.cpp @@ -543,6 +543,7 @@ void wxFileCtrl::OnListEndLabelEdit( wxListEvent &event ) #define ID_TEXT wxID_FILEDLGG + 9 #define ID_LIST_CTRL wxID_FILEDLGG + 10 #define ID_ACTIVATED wxID_FILEDLGG + 11 +#define ID_CHECK wxID_FILEDLGG + 12 IMPLEMENT_DYNAMIC_CLASS(wxFileDialog,wxDialog) @@ -557,6 +558,7 @@ BEGIN_EVENT_TABLE(wxFileDialog,wxDialog) EVT_LIST_ITEM_ACTIVATED(ID_LIST_CTRL, wxFileDialog::OnActivated) EVT_CHOICE(ID_CHOICE,wxFileDialog::OnChoice) EVT_TEXT_ENTER(ID_TEXT,wxFileDialog::OnTextEnter) + EVT_CHECKBOX(ID_CHECK,wxFileDialog::OnCheck) END_EVENT_TABLE() wxFileDialog::wxFileDialog(wxWindow *parent, @@ -668,6 +670,9 @@ wxFileDialog::wxFileDialog(wxWindow *parent, wxBoxSizer *choicesizer = new wxBoxSizer( wxHORIZONTAL ); m_choice = new wxChoice( this, ID_CHOICE ); choicesizer->Add( m_choice, 1, wxCENTER|wxALL, 10 ); + m_check = new wxCheckBox( this, ID_CHECK, _("Show hidden files") ); + m_check->SetValue( FALSE ); + choicesizer->Add( m_check, 0, wxCENTER|wxALL, 10 ); choicesizer->Add( new wxButton( this, wxID_CANCEL, _("Cancel") ), 0, wxCENTER | wxALL, 10 ); mainsizer->Add( choicesizer, 0, wxEXPAND ); @@ -706,6 +711,11 @@ void wxFileDialog::OnChoice( wxCommandEvent &event ) m_list->SetWild( *str ); } +void wxFileDialog::OnCheck( wxCommandEvent &event ) +{ + m_list->ShowHidden( event.GetInt() ); +} + void wxFileDialog::OnActivated( wxListEvent &event ) { HandleAction( event.m_item.m_text ); diff --git a/src/gtk/app.cpp b/src/gtk/app.cpp index b307cdd..4cd1659 100644 --- a/src/gtk/app.cpp +++ b/src/gtk/app.cpp @@ -124,8 +124,13 @@ unsigned char g_palette[64*3] = extern void wxFlushResources(); +/* forward declaration */ +gint wxapp_idle_callback( gpointer WXUNUSED(data) ); +void wxapp_install_idle_handler(); +static gint wxapp_wakeup_timerout_callback( gpointer WXUNUSED(data) ); + //----------------------------------------------------------------------------- -// global functions +// wxExit //----------------------------------------------------------------------------- void wxExit() @@ -133,8 +138,9 @@ void wxExit() gtk_main_quit(); } -/* forward declaration */ -gint wxapp_idle_callback( gpointer WXUNUSED(data) ); +//----------------------------------------------------------------------------- +// wxYield +//----------------------------------------------------------------------------- bool wxYield() { @@ -165,6 +171,20 @@ bool wxYield() return TRUE; } +//----------------------------------------------------------------------------- +// wxWakeUpIdle +//----------------------------------------------------------------------------- + +void wxWakeUpIdle() +{ + if (g_isIdle) + wxapp_install_idle_handler(); +} + +//----------------------------------------------------------------------------- +// local functions +//----------------------------------------------------------------------------- + gint wxapp_idle_callback( gpointer WXUNUSED(data) ) { if (!wxTheApp) return TRUE; @@ -213,9 +233,6 @@ void wxapp_install_idle_handler() #if wxUSE_THREADS -/* forward declaration */ -static gint wxapp_wakeup_timerout_callback( gpointer WXUNUSED(data) ); - void wxapp_install_thread_wakeup() { if (wxTheApp->m_wakeUpTimerTag) return; diff --git a/src/gtk/bmpbuttn.cpp b/src/gtk/bmpbuttn.cpp index 691e691..81f655e 100644 --- a/src/gtk/bmpbuttn.cpp +++ b/src/gtk/bmpbuttn.cpp @@ -43,7 +43,8 @@ extern bool g_blockEventsOnDrag; static void gtk_bmpbutton_clicked_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button ) { - if (g_isIdle) wxapp_install_idle_handler(); + if (g_isIdle) + wxapp_install_idle_handler(); if (!button->m_hasVMT) return; if (g_blockEventsOnDrag) return; diff --git a/src/gtk/tbargtk.cpp b/src/gtk/tbargtk.cpp index c23fc6e..9ee4df2 100644 --- a/src/gtk/tbargtk.cpp +++ b/src/gtk/tbargtk.cpp @@ -123,6 +123,15 @@ static gint gtk_toolbar_enter_callback( GtkWidget *WXUNUSED(widget), } //----------------------------------------------------------------------------- +// InsertChild callback for wxToolBar +//----------------------------------------------------------------------------- + +static void wxInsertChildInToolBar( wxToolBar* WXUNUSED(parent), wxWindow* WXUNUSED(child) ) +{ + /* we don't do anything here but pray */ +} + +//----------------------------------------------------------------------------- // wxToolBar //----------------------------------------------------------------------------- @@ -155,6 +164,7 @@ bool wxToolBar::Create( wxWindow *parent, wxWindowID id, { m_needParent = TRUE; m_blockNextEvent = FALSE; + m_insertCallback = (wxInsertChildFunction)wxInsertChildInToolBar; if (!PreCreation( parent, pos, size ) || !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) @@ -304,7 +314,7 @@ wxToolBarTool *wxToolBar::AddTool( int toolIndex, const wxBitmap& bitmap, GtkWidget *item = gtk_toolbar_append_element ( - GTK_TOOLBAR(m_toolbar), + m_toolbar, ctype, (GtkWidget *)NULL, (const char *)NULL, @@ -332,6 +342,29 @@ wxToolBarTool *wxToolBar::AddTool( int toolIndex, const wxBitmap& bitmap, return tool; } +bool wxToolBar::AddControl(wxControl *control) +{ + wxCHECK_MSG( control, FALSE, wxT("toolbar: can't insert NULL control") ); + + wxCHECK_MSG( control->GetParent() == this, FALSE, + wxT("control must have toolbar as parent") ); + + m_hasToolAlready = TRUE; + + wxToolBarTool *tool = new wxToolBarTool(control); + + gtk_toolbar_append_widget( m_toolbar, control->m_widget, (const char *) NULL, (const char *) NULL ); + + GtkRequisition req; + (* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget)->klass )->size_request ) (m_widget, &req ); + m_width = req.width; + m_height = req.height; + + m_tools.Append( tool ); + + return TRUE; +} + void wxToolBar::AddSeparator() { gtk_toolbar_append_space( m_toolbar ); @@ -635,12 +668,12 @@ void wxToolBar::OnInternalIdle() while (node) { wxToolBarTool *tool = (wxToolBarTool*)node->Data(); - if (!tool->m_item->window) - break; + node = node->Next(); + + if (!tool->m_item || !tool->m_item->window) + continue; else gdk_window_set_cursor( tool->m_item->window, cursor.GetCursor() ); - - node = node->Next(); } } diff --git a/src/gtk1/app.cpp b/src/gtk1/app.cpp index b307cdd..4cd1659 100644 --- a/src/gtk1/app.cpp +++ b/src/gtk1/app.cpp @@ -124,8 +124,13 @@ unsigned char g_palette[64*3] = extern void wxFlushResources(); +/* forward declaration */ +gint wxapp_idle_callback( gpointer WXUNUSED(data) ); +void wxapp_install_idle_handler(); +static gint wxapp_wakeup_timerout_callback( gpointer WXUNUSED(data) ); + //----------------------------------------------------------------------------- -// global functions +// wxExit //----------------------------------------------------------------------------- void wxExit() @@ -133,8 +138,9 @@ void wxExit() gtk_main_quit(); } -/* forward declaration */ -gint wxapp_idle_callback( gpointer WXUNUSED(data) ); +//----------------------------------------------------------------------------- +// wxYield +//----------------------------------------------------------------------------- bool wxYield() { @@ -165,6 +171,20 @@ bool wxYield() return TRUE; } +//----------------------------------------------------------------------------- +// wxWakeUpIdle +//----------------------------------------------------------------------------- + +void wxWakeUpIdle() +{ + if (g_isIdle) + wxapp_install_idle_handler(); +} + +//----------------------------------------------------------------------------- +// local functions +//----------------------------------------------------------------------------- + gint wxapp_idle_callback( gpointer WXUNUSED(data) ) { if (!wxTheApp) return TRUE; @@ -213,9 +233,6 @@ void wxapp_install_idle_handler() #if wxUSE_THREADS -/* forward declaration */ -static gint wxapp_wakeup_timerout_callback( gpointer WXUNUSED(data) ); - void wxapp_install_thread_wakeup() { if (wxTheApp->m_wakeUpTimerTag) return; diff --git a/src/gtk1/bmpbuttn.cpp b/src/gtk1/bmpbuttn.cpp index 691e691..81f655e 100644 --- a/src/gtk1/bmpbuttn.cpp +++ b/src/gtk1/bmpbuttn.cpp @@ -43,7 +43,8 @@ extern bool g_blockEventsOnDrag; static void gtk_bmpbutton_clicked_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button ) { - if (g_isIdle) wxapp_install_idle_handler(); + if (g_isIdle) + wxapp_install_idle_handler(); if (!button->m_hasVMT) return; if (g_blockEventsOnDrag) return; diff --git a/src/gtk1/tbargtk.cpp b/src/gtk1/tbargtk.cpp index c23fc6e..9ee4df2 100644 --- a/src/gtk1/tbargtk.cpp +++ b/src/gtk1/tbargtk.cpp @@ -123,6 +123,15 @@ static gint gtk_toolbar_enter_callback( GtkWidget *WXUNUSED(widget), } //----------------------------------------------------------------------------- +// InsertChild callback for wxToolBar +//----------------------------------------------------------------------------- + +static void wxInsertChildInToolBar( wxToolBar* WXUNUSED(parent), wxWindow* WXUNUSED(child) ) +{ + /* we don't do anything here but pray */ +} + +//----------------------------------------------------------------------------- // wxToolBar //----------------------------------------------------------------------------- @@ -155,6 +164,7 @@ bool wxToolBar::Create( wxWindow *parent, wxWindowID id, { m_needParent = TRUE; m_blockNextEvent = FALSE; + m_insertCallback = (wxInsertChildFunction)wxInsertChildInToolBar; if (!PreCreation( parent, pos, size ) || !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) @@ -304,7 +314,7 @@ wxToolBarTool *wxToolBar::AddTool( int toolIndex, const wxBitmap& bitmap, GtkWidget *item = gtk_toolbar_append_element ( - GTK_TOOLBAR(m_toolbar), + m_toolbar, ctype, (GtkWidget *)NULL, (const char *)NULL, @@ -332,6 +342,29 @@ wxToolBarTool *wxToolBar::AddTool( int toolIndex, const wxBitmap& bitmap, return tool; } +bool wxToolBar::AddControl(wxControl *control) +{ + wxCHECK_MSG( control, FALSE, wxT("toolbar: can't insert NULL control") ); + + wxCHECK_MSG( control->GetParent() == this, FALSE, + wxT("control must have toolbar as parent") ); + + m_hasToolAlready = TRUE; + + wxToolBarTool *tool = new wxToolBarTool(control); + + gtk_toolbar_append_widget( m_toolbar, control->m_widget, (const char *) NULL, (const char *) NULL ); + + GtkRequisition req; + (* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget)->klass )->size_request ) (m_widget, &req ); + m_width = req.width; + m_height = req.height; + + m_tools.Append( tool ); + + return TRUE; +} + void wxToolBar::AddSeparator() { gtk_toolbar_append_space( m_toolbar ); @@ -635,12 +668,12 @@ void wxToolBar::OnInternalIdle() while (node) { wxToolBarTool *tool = (wxToolBarTool*)node->Data(); - if (!tool->m_item->window) - break; + node = node->Next(); + + if (!tool->m_item || !tool->m_item->window) + continue; else gdk_window_set_cursor( tool->m_item->window, cursor.GetCursor() ); - - node = node->Next(); } } -- 2.7.4