Get the attributes of a PtMultiText widget
PtMultiTextAttributes_t *
PtMultiTextGetAttributes(
PtWidget_t *widget,
int char_offset,
PtMultiTextAttributes_t *attributes,
int *start,
int *end );
This function sets the provided PtMultiTextAttributes_t structure to the attributes found at char_offset.
If you provide the integers for start and end, the function sets these parameters to the character offsets that mark the beginning and end of the segment that contains char_offset. Both start and end are 0-based. So, for example, if *start is set to 0, it indicates the first character in the widget's text buffer.
A pointer to the provided PtMultiTextAttributes_t structure, or NULL if the specified widget is NULL or isn't a PtMultiText widget.
/* Standard headers */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
/* Toolkit headers */
#include <Ph.h>
#include <Pt.h>
#include <Ap.h>
/* Local headers */
#include "editor.h"
#include "abimport.h"
#include "proto.h"
int
save( PtWidget_t *widget, ApInfo_t *apinfo,
PtCallbackInfo_t *cbinfo )
{
PtArg_t argt;
FILE *fp;
char *text;
PtMultiTextAttributes_t attrs;
int start = 0, end = 0, len;
if( !(fp = fopen( "notepad", "w" ) ) )
return Pt_CONTINUE;
PtSetArg( &argt, Pt_ARG_TEXT_STRING, &text, 0 );
PtGetResources( ABW_text, 1, &argt );
len = strlen( text ) + 1;
fwrite( &len, sizeof( len ), 1, fp );
fwrite( text, len, 1, fp );
PtMultiTextGetAttributes( ABW_text, start,
&attrs, NULL, &end );
while( end > start )
{
fwrite( &start, sizeof( start ), 1, fp);
fwrite( &end, sizeof( end ), 1, fp);
fwrite( &attrs, sizeof( attrs ), 1, fp );
if( attrs.font )
{ len = strlen( attrs.font ) +1;
fwrite( &len, sizeof( len ), 1, fp );
fwrite( attrs.font, len, 1, fp );
}
start = end;
PtMultiTextGetAttributes( ABW_text, start,
&attrs, NULL, &end );
}
fclose( fp );
widget = widget, apinfo = apinfo, cbinfo = cbinfo;
return Pt_CONTINUE;
}
int load( PtWidget_t *widget, ApInfo_t *apinfo,
PtCallbackInfo_t *cbinfo )
{
PtArg_t argt;
FILE *fp;
char *text;
PtMultiTextAttributes_t attrs;
int start = -1, end = 0, len;
if( !(fp = fopen( "notepad", "r" ) ) )
return Pt_CONTINUE;
fread( &len, sizeof( len ), 1, fp );
if( !( text = (char *) malloc( len ) ) )
return Pt_CONTINUE;
fread( text, len, 1, fp );
PtSetArg( &argt, Pt_ARG_TEXT_STRING, text, 0 );
PtSetResources( ABW_text, 1, &argt );
free( text );
while( fread( &start, sizeof( start ), 1, fp ) )
{
fread( &end, sizeof( end ), 1, fp );
fread( &attrs, sizeof( attrs ), 1, fp );
if( attrs.font )
{ fread( &len, sizeof( len ), 1, fp );
attrs.font = (char *) malloc( len );
fread( attrs.font, len, 1, fp );
}
PtMultiTextModifyAttributes( ABW_text, start,
end, &attrs, -1 );
if( attrs.font )
free( attrs.font );
}
fclose( fp );
widget = widget, apinfo = apinfo, cbinfo = cbinfo;
return Pt_CONTINUE;
}
Photon
| Safety: | |
|---|---|
| Interrupt handler | No |
| Signal handler | No |
| Thread | No |
PtMultiTextCreateAttributes(), PtTextGetSelection(), PtTextModifyText(), PtTextSetSelection(), PtMultiTextAttributes_t