From 75ce0581545a6c151484e488596ed200c2ffd93e Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Thu, 28 Jan 1999 18:25:36 +0000 Subject: [PATCH] Removed wxNullRegion Finalized wxClpboard git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1508 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/clipbrd.tex | 54 +++++++++-------- include/wx/gdicmn.h | 3 - include/wx/gtk/clipbrd.h | 12 +++- include/wx/gtk1/clipbrd.h | 12 +++- samples/controls/controls.cpp | 27 +++++---- src/gtk/clipbrd.cpp | 109 ++++++++++++++++++++-------------- src/gtk/data.cpp | 1 - src/gtk1/clipbrd.cpp | 109 ++++++++++++++++++++-------------- src/gtk1/data.cpp | 1 - 9 files changed, 196 insertions(+), 132 deletions(-) diff --git a/docs/latex/wx/clipbrd.tex b/docs/latex/wx/clipbrd.tex index a97e1ed478..25c8fe089f 100644 --- a/docs/latex/wx/clipbrd.tex +++ b/docs/latex/wx/clipbrd.tex @@ -6,7 +6,7 @@ clipboard class from wxWindows 1.xx, which has the same name but a different imp To use the clipboard, you call member functions of the global {\bf wxTheClipboard} object. Call \helpref{wxClipboard::Open}{wxclipboardopen} to get ownership of the clipboard. If this operation returns TRUE, you -now own the clipboard. Call \helpref{wxClipboard::SetData}{wxclipboardsetdata} to put data +now own the clipboard. Call \helpref{wxClipboard::AddData}{wxclipboardadddata} to put data on the clipboard (one or more times), or \helpref{wxClipboard::GetData}{wxclipboardgetdata} to retrieve data from the clipboard. Call \helpref{wxClipboard::Close}{wxclipboardclose} to close the clipboard and relinquish ownership. You should keep the clipboard open only momentarily. @@ -17,20 +17,22 @@ For example: // Write some text to the clipboard if (wxTheClipboard->Open()) { - // This object is held by the clipboard, so do not delete it in the app. - wxTextDataObject* object = new wxTextDataObject("Some text"); - wxTheClipboard->SetData(& object); + // This data objects are held by the clipboard, + // so do not delete them in the app. + wxTheClipboard->AddData( new wxTextDataObject("Some text") ); wxTheClipboard->Close(); } // Read some text - if (wxTheClipboard->Open() && wxTheClipboard->IsSupportedFormat(wxDF_TEXT)) + if (wxTheClipboard->Open()) { - wxTextDataObject object; - wxTheClipboard->GetData(& object); + wxTextDataObject data; + if (wxTheClipboard->IsSupported(data)) + { + wxTheClipboard->GetData(data); + wxMessageBox(data.GetText()); + } wxTheClipboard->Close(); - - wxMessageBox(object.GetText()); } \end{verbatim} @@ -56,6 +58,13 @@ Constructor. Destructor. +\membersection{wxClipboard::AddData}\label{wxclipboardadddata} + +\func{bool}{AddData}{\param{wxDataObject*}{ data}} + +Call this function to add a data object to the clipboard. This function can be called several times +to put different formats on the clipboard. + \membersection{wxClipboard::Clear}\label{wxclipboardclear} \func{void}{Clear}{\void} @@ -66,26 +75,20 @@ Clears the global clipboard object and the system's clipboard if possible. \func{bool}{Close}{\void} -Call this function to close the clipboard, having opened it with \helpref{wxClipboard::Close}{wxclipboardclose}. +Call this function to close the clipboard, having opened it with \helpref{wxClipboard::Open}{wxclipboardopen}. \membersection{wxClipboard::GetData}\label{wxclipboardgetdata} -\func{bool}{GetData}{\param{wxDataObject*}{ data}} +\func{bool}{GetData}{\param{wxDataObject&}{ data}} Call this function to fill {\it data} with data on the clipboard, if available in the required -format. +format. Returns TRUE on success. -\membersection{wxClipboard::IsSupportedFormat}\label{wxclipboardissupportedformat} +\membersection{wxClipboard::IsSupported}\label{wxclipboardissupported} -\func{bool}{IsSupportedFormat}{\param{wxDataFormat}{ format}, \param{const wxString\&}{ id = ""}} +\func{bool}{IsSupported}{\param{wxDataObject&}{ data}} -Returns TRUE if the given format is available on the clipboard. - -\wxheading{Parameters} - -\docparam{format}{The format. See \helpref{wxDataObject}{wxdataobject} for a list of formats.} - -\docparam{id}{ If {\it format} is wxDF\_PRIVATE, {\it id} is the identifier of the private data format.} +Returns TRUE if the format of the given data object is available on the clipboard. \membersection{wxClipboard::Open}\label{wxclipboardopen} @@ -97,10 +100,13 @@ and \helpref{wxClipboard::GetData}{wxclipboardgetdata}. Call \helpref{wxClipboard::Close}{wxclipboardclose} when you have finished with the clipboard. You should keep the clipboard open for only a very short time. -\membersection{wxClipboard::SetData}\label{wxclipboardsetdata} +Returns TRUE on success. This should be tested (as in the sample shown above). + +\membersection{wxClipboard::SetData}\label{wxclipboardadddata} \func{bool}{SetData}{\param{wxDataObject*}{ data}} -Call this function to set a data object to the clipboard. This function can be called several times -to put different formats on the clipboard. +Call this function to set the data object to the clipboard. This function will +clear all previous contents in the clipboard, so calling it several times +does not make any sense. diff --git a/include/wx/gdicmn.h b/include/wx/gdicmn.h index fe82c80e4f..9b97b7d0f8 100644 --- a/include/wx/gdicmn.h +++ b/include/wx/gdicmn.h @@ -305,9 +305,6 @@ WXDLLEXPORT_DATA(extern wxBrush) wxNullBrush; WXDLLEXPORT_DATA(extern wxPalette) wxNullPalette; WXDLLEXPORT_DATA(extern wxFont) wxNullFont; WXDLLEXPORT_DATA(extern wxColour) wxNullColour; -#ifdef __WXGTK__ -WXDLLEXPORT_DATA(extern wxRegion) wxNullRegion; -#endif // Stock cursors types WXDLLEXPORT_DATA(extern wxCursor*) wxSTANDARD_CURSOR; diff --git a/include/wx/gtk/clipbrd.h b/include/wx/gtk/clipbrd.h index 55a9e8f462..e880b5ffaa 100644 --- a/include/wx/gtk/clipbrd.h +++ b/include/wx/gtk/clipbrd.h @@ -57,11 +57,17 @@ public: /* close the clipboard after SetData() and GetData() */ virtual void Close(); - /* set the clipboard data. the clipboard will delete the broker later */ - virtual bool SetData( wxDataBroker *data ); + /* set the clipboard data. all other formats will be deleted. */ + virtual bool SetData( wxDataObject *data ); + /* add to the clipboard data. */ + virtual bool AddData( wxDataObject *data ); + + /* ask if data in correct format is available */ + virtual bool IsSupported( wxDataObject &data ); + /* fill data with data on the clipboard (if available) */ - virtual bool GetData( wxDataObject *data ); + virtual bool GetData( wxDataObject &data ); /* clears wxTheClipboard and the system's clipboard if possible */ virtual void Clear(); diff --git a/include/wx/gtk1/clipbrd.h b/include/wx/gtk1/clipbrd.h index 55a9e8f462..e880b5ffaa 100644 --- a/include/wx/gtk1/clipbrd.h +++ b/include/wx/gtk1/clipbrd.h @@ -57,11 +57,17 @@ public: /* close the clipboard after SetData() and GetData() */ virtual void Close(); - /* set the clipboard data. the clipboard will delete the broker later */ - virtual bool SetData( wxDataBroker *data ); + /* set the clipboard data. all other formats will be deleted. */ + virtual bool SetData( wxDataObject *data ); + /* add to the clipboard data. */ + virtual bool AddData( wxDataObject *data ); + + /* ask if data in correct format is available */ + virtual bool IsSupported( wxDataObject &data ); + /* fill data with data on the clipboard (if available) */ - virtual bool GetData( wxDataObject *data ); + virtual bool GetData( wxDataObject &data ); /* clears wxTheClipboard and the system's clipboard if possible */ virtual void Clear(); diff --git a/samples/controls/controls.cpp b/samples/controls/controls.cpp index 88f1d757fa..9c9a7b35d7 100644 --- a/samples/controls/controls.cpp +++ b/samples/controls/controls.cpp @@ -482,7 +482,7 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) : // panel->SetForegroundColour("blue"); m_radio = new wxRadioBox( panel, ID_RADIOBOX, "That", wxPoint(10,160), wxSize(-1,-1), 2, choices2, 1, wxRA_SPECIFY_ROWS ); // m_radio->SetBackgroundColour("wheat"); - m_radio = new wxRadioBox( panel, ID_RADIOBOX, "This", wxPoint(10,10), wxSize(-1,-1), 5, choices, 1, wxRA_SPECIFY_COLS ); + m_radio = new wxRadioBox( panel, ID_RADIOBOX, "This", wxPoint(10,10), wxSize(-1,-1), 5, choices, 2, wxRA_SPECIFY_COLS ); // m_radio->SetBackgroundColour("wheat"); (void)new wxButton( panel, ID_RADIOBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) ); (void)new wxButton( panel, ID_RADIOBOX_SEL_STR, "Select 'This'", wxPoint(180,80), wxSize(140,30) ); @@ -547,24 +547,31 @@ void MyPanel::OnPasteFromClipboard( wxCommandEvent &WXUNUSED(event) ) *m_text << "Successfully opened the clipboard." << "\n"; } - wxTextDataObject *data = new wxTextDataObject(); + wxTextDataObject data; - if (wxTheClipboard->GetData( data )) + if (wxTheClipboard->IsSupported( data )) { - *m_text << "Successfully retrieved data from the clipboard." << "\n"; - *m_multitext << data->GetText() << "\n"; + *m_text << "Clipboard supports requested format." << "\n"; + + if (wxTheClipboard->GetData( data )) + { + *m_text << "Successfully retrieved data from the clipboard." << "\n"; + *m_multitext << data.GetText() << "\n"; + } + else + { + *m_text << "Error getting data from the clipboard." << "\n"; + } } else { - *m_text << "Error getting data from the clipboard." << "\n"; + *m_text << "Clipboard doesn't support requested format." << "\n"; } wxTheClipboard->Close(); *m_text << "Closed the clipboard." << "\n"; - delete data; - #endif } @@ -588,10 +595,8 @@ void MyPanel::OnCopyToClipboard( wxCommandEvent &WXUNUSED(event) ) } wxTextDataObject *data = new wxTextDataObject( text ); - wxDataBroker *broker = new wxDataBroker(); - broker->Add( data ); - if (!wxTheClipboard->SetData( broker )) + if (!wxTheClipboard->SetData( data )) { *m_text << "Error while copying to the clipboard." << "\n"; } diff --git a/src/gtk/clipbrd.cpp b/src/gtk/clipbrd.cpp index 11096c3a4c..99ce0ac8b8 100644 --- a/src/gtk/clipbrd.cpp +++ b/src/gtk/clipbrd.cpp @@ -344,68 +344,74 @@ bool wxClipboard::Open() return TRUE; } -bool wxClipboard::SetData( wxDataBroker *data ) +bool wxClipboard::SetData( wxDataObject *data ) { + wxCHECK_MSG( m_open, FALSE, "clipboard not open" ); + wxCHECK_MSG( data, FALSE, "data is invalid" ); Clear(); + + return AddData( data ); +} + +bool wxClipboard::AddData( wxDataObject *data ) +{ + wxCHECK_MSG( m_open, FALSE, "clipboard not open" ); - m_dataBroker = data; + wxCHECK_MSG( data, FALSE, "data is invalid" ); - if (!m_dataBroker) return FALSE; + /* if clipboard has been cleared before, create new data broker */ - wxCHECK_MSG( m_open, FALSE, "clipboard not open" ); + if (!m_dataBroker) m_dataBroker = new wxDataBroker(); - wxNode *node = m_dataBroker->m_dataObjects.First(); - while (node) - { - wxDataObject *dobj = (wxDataObject*)node->Data(); - - GdkAtom format = dobj->GetFormat().GetAtom(); + /* add new data to list of offered data objects */ + + m_dataBroker->Add( data ); + + /* get native format id of new data object */ + + GdkAtom format = data->GetFormat().GetAtom(); - if (format != (GdkAtom) 0) - { - /* This should happen automatically */ + wxCHECK_MSG( format, FALSE, "data has invalid format" ); + + /* This should happen automatically, but to be on the safe side */ - m_ownsClipboard = FALSE; - m_ownsPrimarySelection = FALSE; + m_ownsClipboard = FALSE; + m_ownsPrimarySelection = FALSE; - /* Add handlers if someone requests data */ + /* Add handlers if someone requests data */ - gtk_selection_add_handler( m_clipboardWidget, + gtk_selection_add_handler( m_clipboardWidget, g_clipboardAtom, format, selection_handler, (gpointer) NULL ); - gtk_selection_add_handler( m_clipboardWidget, + gtk_selection_add_handler( m_clipboardWidget, GDK_SELECTION_PRIMARY, format, selection_handler, (gpointer) NULL ); - /* Tell the world we offer clipboard data */ + /* Tell the world we offer clipboard data */ - if (!gtk_selection_owner_set( m_clipboardWidget, + if (!gtk_selection_owner_set( m_clipboardWidget, g_clipboardAtom, GDK_CURRENT_TIME )) - { - return FALSE; - } - m_ownsClipboard = TRUE; + { + return FALSE; + } + m_ownsClipboard = TRUE; - if (!gtk_selection_owner_set( m_clipboardWidget, + if (!gtk_selection_owner_set( m_clipboardWidget, GDK_SELECTION_PRIMARY, GDK_CURRENT_TIME )) - { - return FALSE; - } - m_ownsPrimarySelection = TRUE; - } - - node = node->Next(); + { + return FALSE; } - + m_ownsPrimarySelection = TRUE; + return TRUE; } @@ -416,22 +422,16 @@ void wxClipboard::Close() m_open = FALSE; } -bool wxClipboard::GetData( wxDataObject *data ) +bool wxClipboard::IsSupported( wxDataObject &data ) { wxCHECK_MSG( m_open, FALSE, "clipboard not open" ); - m_receivedData = data; - - wxCHECK_MSG( m_receivedData, FALSE, "invalid data object" ); + /* store requested format to be asked for by callbacks */ - /* STEP ONE: check if there is such data in the clipboard */ - - m_targetRequested = data->GetFormat().GetAtom(); + m_targetRequested = data.GetFormat().GetAtom(); wxCHECK_MSG( m_targetRequested, FALSE, "invalid clipboard format" ); - if (m_targetRequested == 0) return FALSE; - /* add handler for target (= format) query */ gtk_signal_connect( GTK_OBJECT(m_clipboardWidget), @@ -454,8 +454,29 @@ bool wxClipboard::GetData( wxDataObject *data ) (gpointer) this ); if (!m_formatSupported) return FALSE; + + return TRUE; +} + +bool wxClipboard::GetData( wxDataObject &data ) +{ + wxCHECK_MSG( m_open, FALSE, "clipboard not open" ); + + /* is data supported by clipboard ? */ + + if (!IsSupported( data )) return FALSE; + + /* store pointer to data object to be filled up by callbacks */ + + m_receivedData = &data; + + /* store requested format to be asked for by callbacks */ + + m_targetRequested = data.GetFormat().GetAtom(); - /* STEP TWO: get the data from the clipboard */ + wxCHECK_MSG( m_targetRequested, FALSE, "invalid clipboard format" ); + + /* start query */ m_formatSupported = FALSE; @@ -464,6 +485,8 @@ bool wxClipboard::GetData( wxDataObject *data ) GTK_SIGNAL_FUNC( selection_received ), (gpointer) this ); + /* ask for clipboard contents */ + gtk_selection_convert( m_clipboardWidget, g_clipboardAtom, m_targetRequested, diff --git a/src/gtk/data.cpp b/src/gtk/data.cpp index 8a6969b3a9..324dc713bc 100644 --- a/src/gtk/data.cpp +++ b/src/gtk/data.cpp @@ -124,7 +124,6 @@ wxBrush wxNullBrush; wxFont wxNullFont; wxColour wxNullColour; wxPalette wxNullPalette; -wxRegion wxNullRegion; /* Default window names */ const char *wxButtonNameStr = "button"; diff --git a/src/gtk1/clipbrd.cpp b/src/gtk1/clipbrd.cpp index 11096c3a4c..99ce0ac8b8 100644 --- a/src/gtk1/clipbrd.cpp +++ b/src/gtk1/clipbrd.cpp @@ -344,68 +344,74 @@ bool wxClipboard::Open() return TRUE; } -bool wxClipboard::SetData( wxDataBroker *data ) +bool wxClipboard::SetData( wxDataObject *data ) { + wxCHECK_MSG( m_open, FALSE, "clipboard not open" ); + wxCHECK_MSG( data, FALSE, "data is invalid" ); Clear(); + + return AddData( data ); +} + +bool wxClipboard::AddData( wxDataObject *data ) +{ + wxCHECK_MSG( m_open, FALSE, "clipboard not open" ); - m_dataBroker = data; + wxCHECK_MSG( data, FALSE, "data is invalid" ); - if (!m_dataBroker) return FALSE; + /* if clipboard has been cleared before, create new data broker */ - wxCHECK_MSG( m_open, FALSE, "clipboard not open" ); + if (!m_dataBroker) m_dataBroker = new wxDataBroker(); - wxNode *node = m_dataBroker->m_dataObjects.First(); - while (node) - { - wxDataObject *dobj = (wxDataObject*)node->Data(); - - GdkAtom format = dobj->GetFormat().GetAtom(); + /* add new data to list of offered data objects */ + + m_dataBroker->Add( data ); + + /* get native format id of new data object */ + + GdkAtom format = data->GetFormat().GetAtom(); - if (format != (GdkAtom) 0) - { - /* This should happen automatically */ + wxCHECK_MSG( format, FALSE, "data has invalid format" ); + + /* This should happen automatically, but to be on the safe side */ - m_ownsClipboard = FALSE; - m_ownsPrimarySelection = FALSE; + m_ownsClipboard = FALSE; + m_ownsPrimarySelection = FALSE; - /* Add handlers if someone requests data */ + /* Add handlers if someone requests data */ - gtk_selection_add_handler( m_clipboardWidget, + gtk_selection_add_handler( m_clipboardWidget, g_clipboardAtom, format, selection_handler, (gpointer) NULL ); - gtk_selection_add_handler( m_clipboardWidget, + gtk_selection_add_handler( m_clipboardWidget, GDK_SELECTION_PRIMARY, format, selection_handler, (gpointer) NULL ); - /* Tell the world we offer clipboard data */ + /* Tell the world we offer clipboard data */ - if (!gtk_selection_owner_set( m_clipboardWidget, + if (!gtk_selection_owner_set( m_clipboardWidget, g_clipboardAtom, GDK_CURRENT_TIME )) - { - return FALSE; - } - m_ownsClipboard = TRUE; + { + return FALSE; + } + m_ownsClipboard = TRUE; - if (!gtk_selection_owner_set( m_clipboardWidget, + if (!gtk_selection_owner_set( m_clipboardWidget, GDK_SELECTION_PRIMARY, GDK_CURRENT_TIME )) - { - return FALSE; - } - m_ownsPrimarySelection = TRUE; - } - - node = node->Next(); + { + return FALSE; } - + m_ownsPrimarySelection = TRUE; + return TRUE; } @@ -416,22 +422,16 @@ void wxClipboard::Close() m_open = FALSE; } -bool wxClipboard::GetData( wxDataObject *data ) +bool wxClipboard::IsSupported( wxDataObject &data ) { wxCHECK_MSG( m_open, FALSE, "clipboard not open" ); - m_receivedData = data; - - wxCHECK_MSG( m_receivedData, FALSE, "invalid data object" ); + /* store requested format to be asked for by callbacks */ - /* STEP ONE: check if there is such data in the clipboard */ - - m_targetRequested = data->GetFormat().GetAtom(); + m_targetRequested = data.GetFormat().GetAtom(); wxCHECK_MSG( m_targetRequested, FALSE, "invalid clipboard format" ); - if (m_targetRequested == 0) return FALSE; - /* add handler for target (= format) query */ gtk_signal_connect( GTK_OBJECT(m_clipboardWidget), @@ -454,8 +454,29 @@ bool wxClipboard::GetData( wxDataObject *data ) (gpointer) this ); if (!m_formatSupported) return FALSE; + + return TRUE; +} + +bool wxClipboard::GetData( wxDataObject &data ) +{ + wxCHECK_MSG( m_open, FALSE, "clipboard not open" ); + + /* is data supported by clipboard ? */ + + if (!IsSupported( data )) return FALSE; + + /* store pointer to data object to be filled up by callbacks */ + + m_receivedData = &data; + + /* store requested format to be asked for by callbacks */ + + m_targetRequested = data.GetFormat().GetAtom(); - /* STEP TWO: get the data from the clipboard */ + wxCHECK_MSG( m_targetRequested, FALSE, "invalid clipboard format" ); + + /* start query */ m_formatSupported = FALSE; @@ -464,6 +485,8 @@ bool wxClipboard::GetData( wxDataObject *data ) GTK_SIGNAL_FUNC( selection_received ), (gpointer) this ); + /* ask for clipboard contents */ + gtk_selection_convert( m_clipboardWidget, g_clipboardAtom, m_targetRequested, diff --git a/src/gtk1/data.cpp b/src/gtk1/data.cpp index 8a6969b3a9..324dc713bc 100644 --- a/src/gtk1/data.cpp +++ b/src/gtk1/data.cpp @@ -124,7 +124,6 @@ wxBrush wxNullBrush; wxFont wxNullFont; wxColour wxNullColour; wxPalette wxNullPalette; -wxRegion wxNullRegion; /* Default window names */ const char *wxButtonNameStr = "button"; -- 2.45.2