tbx  0.7.6
Public Member Functions | Static Public Member Functions | List of all members
tbx::ext::OleClient Class Reference

Class to provide an OleClient to edit a document externally for an application. More...

#include <oleclient.h>

Inheritance diagram for tbx::ext::OleClient:
tbx::WimpAcknowledgeMessageListener tbx::WimpUserMessageListener

Public Member Functions

 OleClient (int file_type, const char *temp_prefix=0)
 Construct OleClient for a file type. More...
 
bool find_server (bool use_ole_support=true)
 Find the server for this OleClient. More...
 
std::string get_scrap_file_name ()
 Get file name suitable for scrap file for edit session. More...
 
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. More...
 
void edit_text (std::string text, tbx::Window file_window, int x_offset, int y_offset, OleClientHandler *handler)
 Edit the given text using OLE. More...
 
void closed_in_client ()
 Called to close OLE editing from the client.
 
bool delete_file () const
 Check if file should be deleted. More...
 
void delete_file (bool del)
 Set if file used to pass data to OLE server should be deleted when editing session is closed. More...
 
bool in_progress () const
 Check if OLE edit is in progress. More...
 
virtual void acknowledge_message (tbx::WimpMessageEvent &event)
 Handle OLE acknowledge message.
 
virtual void user_message (tbx::WimpMessageEvent &event)
 Handle messages from the OLE server.
 

Static Public Member Functions

static void client_closed ()
 Client application has closed so broadcast a message to close any open OLE sessions in the third party applications. More...
 
static int open_count ()
 Return the number of currently open OLE sessions.
 

Detailed Description

Class to provide an OleClient to edit a document externally for an application.

An application that supports OLE editing for the given file type needs to have been seen by the filer.

The find_server method will also attempt to use the OLESupport module (if available in !System) if no other OLE server is registered for the file type.

Pseudo code example of use OleClient text_client(0xFFF); // 0xFFF is file type for text files

if (text_client.find_server()) { std::string temp_file = text_client.get_scrap_file_name(); // Save data to be edited to the file std::ofstream os(temp_file); os << text_to_be_edited; os.close();

text_client.edit_file(temp_name, from_window, 0, 0, my_handler) // see OleClientHandler for how to proceed

// A shortcut has been provided to just edit text in a string text_client.edit_text(text_to_be_edited, from_window, 0, 0, my_handler) }

Constructor & Destructor Documentation

◆ OleClient()

tbx::ext::OleClient::OleClient ( int  file_type,
const char *  temp_prefix = 0 
)

Construct OleClient for a file type.

Parameters
file_typeType of file to use client
temp_prefixprefix used for temporary file used in edit (or 0 for application directory name)

Member Function Documentation

◆ client_closed()

void tbx::ext::OleClient::client_closed ( )
static

Client application has closed so broadcast a message to close any open OLE sessions in the third party applications.

Does nothing if no sessions are open

◆ delete_file() [1/2]

bool tbx::ext::OleClient::delete_file ( ) const
inline

Check if file should be deleted.

Returns
true if file used to pass data to OLE server should be deleted when editing session is closed

◆ delete_file() [2/2]

void tbx::ext::OleClient::delete_file ( bool  del)
inline

Set if file used to pass data to OLE server should be deleted when editing session is closed.

This is normally false, but is set to true by the edit_text method.

Parameters
deltrue if file should be deleted when closed

◆ edit_file()

void tbx::ext::OleClient::edit_file ( std::string  file_name,
tbx::Window  file_window,
int  x_offset,
int  y_offset,
OleClientHandler handler 
)

Edit the given file using OLE.

If editing a part of the document a suitable file name can be obtained from the get_scrap_file_name method. If the file is temporary, set delete_file(true) if you want the client to delete the file after use.

Parameters
file_namethe name of the file containing the value to edit
file_windowthe window the text is from
x_offsetthe x-coordinate of the text in the window (or 0 if none)
y_offsetthe y-coordinate of the text in the window (or 0 if none)
handlerOleClientHandler to be informed of progress and updates to the text

◆ edit_text()

void tbx::ext::OleClient::edit_text ( std::string  text,
tbx::Window  file_window,
int  x_offset,
int  y_offset,
OleClientHandler handler 
)

Edit the given text using OLE.

The text is written to a temporary file (which will be deleted at the end of the session).

Parameters
textthe text to edit
file_windowthe window the text is from
x_offsetthe x-coordinate of the text in the window (or 0 if none)
y_offsetthe y-coordinate of the text in the window (or 0 if none)
handlerOleClientHandler to be informed of progress and updates to the text

◆ find_server()

bool tbx::ext::OleClient::find_server ( bool  use_ole_support = true)

Find the server for this OleClient.

Should be called before each edit as the server may change during the lifetime of the application.

Parameters
use_ole_supportuse OLESupport module if no registered server

◆ get_scrap_file_name()

std::string tbx::ext::OleClient::get_scrap_file_name ( )

Get file name suitable for scrap file for edit session.

A new file name is returned with every call.

Returns
temporary file name in Wimp scrap directory

◆ in_progress()

bool tbx::ext::OleClient::in_progress ( ) const
inline

Check if OLE edit is in progress.

Returns
true if the edit is in progress

The documentation for this class was generated from the following files: