tbx  0.7.6
oleclient.h
1 /*
2  * tbx RISC OS toolbox library
3  *
4  * Copyright (C) 2014 Alan Buckley All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 
25 #ifndef TBX_EXT_OLECLIENT_H
26 #define TBX_EXT_OLECLIENT_H
27 
28 #include <string>
29 #include "../wimpmessagelistener.h"
30 #include "../window.h"
31 
32 namespace tbx
33 {
34 namespace ext
35 {
36 
37 class OleClientHandler;
38 
68 class OleClient :
71 {
72  int _file_type;
73  std::string _tmp_prefix;
74  OleClientHandler *_handler;
75  int _session_id;
76  static int _next_session_id;
77  std::string _server_name;
78  std::string _server_start;
79  bool _text_edit;
80  std::string _file_name;
81  int _my_ref;
82  int _editor_task;
83  bool _in_progress;
84  bool _delete_file;
85  static int _open_count;
86 
87  public:
88  OleClient(int file_type, const char *temp_prefix = 0);
89  ~OleClient(); // TIDY up
90 
91  static void client_closed();
95  static int open_count() {return _open_count;}
96 
97  bool find_server(bool use_ole_support = true);
98  std::string get_scrap_file_name();
99 
100  void edit_file(std::string file_name, tbx::Window file_window, int x_offset, int y_offset, OleClientHandler *handler);
101  void edit_text(std::string text, tbx::Window file_window, int x_offset, int y_offset, OleClientHandler *handler);
102 
103  void closed_in_client();
104 
111  bool delete_file() const {return _delete_file;}
121  void delete_file(bool del) {_delete_file = del;}
122 
128  bool in_progress() const {return _in_progress;}
129 
130  virtual void acknowledge_message(tbx::WimpMessageEvent &event);
131  virtual void user_message(tbx::WimpMessageEvent &event);
132 
133  private:
134  void edit_finished();
135 };
136 
142 {
143 public:
144  virtual ~OleClientHandler() {};
145 
151  virtual void failed_to_start_server(OleClient &client) = 0;
157  virtual void edit_started(OleClient &client) {}
163  virtual void edit_closed(OleClient &client) {}
171  virtual void edit_text_changed(OleClient &client, const std::string &text) {}
179  virtual void edit_file_changed(OleClient &client, const std::string &file_name) {}
180 };
181 
182 }
183 }
184 
185 #endif
tbx
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:35
tbx::Window
The Window object represents a toolbox window.
Definition: window.h:70
tbx::ext::OleClientHandler::edit_file_changed
virtual void edit_file_changed(OleClient &client, const std::string &file_name)
Called when the file has been saved in the OLE server (when edit_file was called).
Definition: oleclient.h:179
tbx::ext::OleClientHandler::failed_to_start_server
virtual void failed_to_start_server(OleClient &client)=0
Called if attempt to start the OLE server failed.
tbx::ext::OleClient::OleClient
OleClient(int file_type, const char *temp_prefix=0)
Construct OleClient for a file type.
Definition: oleclient.cc:51
tbx::ext::OleClient::edit_text
void edit_text(std::string text, tbx::Window file_window, int x_offset, int y_offset, OleClientHandler *handler)
Edit the given text using OLE.
Definition: oleclient.cc:190
tbx::ext::OleClient::delete_file
void delete_file(bool del)
Set if file used to pass data to OLE server should be deleted when editing session is closed.
Definition: oleclient.h:121
tbx::ext::OleClientHandler
Interface called back from OleServer to inform of state of edited file.
Definition: oleclient.h:142
tbx::ext::OleClientHandler::edit_closed
virtual void edit_closed(OleClient &client)
Called when the OLE editor has been closed.
Definition: oleclient.h:163
tbx::ext::OleClient::in_progress
bool in_progress() const
Check if OLE edit is in progress.
Definition: oleclient.h:128
tbx::ext::OleClientHandler::edit_started
virtual void edit_started(OleClient &client)
Called once the OLE edit has successfully started.
Definition: oleclient.h:157
tbx::ext::OleClient::get_scrap_file_name
std::string get_scrap_file_name()
Get file name suitable for scrap file for edit session.
Definition: oleclient.cc:173
tbx::ext::OleClient::closed_in_client
void closed_in_client()
Called to close OLE editing from the client.
Definition: oleclient.cc:342
tbx::ext::OleClient::client_closed
static void client_closed()
Client application has closed so broadcast a message to close any open OLE sessions in the third part...
Definition: oleclient.cc:389
tbx::WimpUserMessageListener
Listener to handle WimpUserMessages (event code 17)
Definition: wimpmessagelistener.h:253
tbx::ext::OleClient::delete_file
bool delete_file() const
Check if file should be deleted.
Definition: oleclient.h:111
tbx::WimpMessageEvent
Wimp message received event.
Definition: wimpmessagelistener.h:210
tbx::ext::OleClient
Class to provide an OleClient to edit a document externally for an application.
Definition: oleclient.h:71
tbx::ext::OleClient::open_count
static int open_count()
Return the number of currently open OLE sessions.
Definition: oleclient.h:95
tbx::ext::OleClientHandler::edit_text_changed
virtual void edit_text_changed(OleClient &client, const std::string &text)
Called with the new text from the OLE server if the the edit was started using the edit_text method.
Definition: oleclient.h:171
tbx::ext::OleClient::edit_file
void edit_file(std::string file_name, tbx::Window file_window, int x_offset, int y_offset, OleClientHandler *handler)
Edit the given file using OLE.
Definition: oleclient.cc:213
tbx::ext::OleClient::acknowledge_message
virtual void acknowledge_message(tbx::WimpMessageEvent &event)
Handle OLE acknowledge message.
Definition: oleclient.cc:252
tbx::WimpAcknowledgeMessageListener
Listener to handle WimpAcnowledgeMessages (event code 19)
Definition: wimpmessagelistener.h:290
tbx::ext::OleClient::find_server
bool find_server(bool use_ole_support=true)
Find the server for this OleClient.
Definition: oleclient.cc:93
tbx::ext::OleClient::user_message
virtual void user_message(tbx::WimpMessageEvent &event)
Handle messages from the OLE server.
Definition: oleclient.cc:290