Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/photon/widget_ref/pt/ptmultitextgetattributes.html on line 1

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/photon/widget_ref/pt/ptmultitextgetattributes.html on line 1

Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/photon/widget_ref/pt/ptmultitextgetattributes.html on line 8

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/photon/widget_ref/pt/ptmultitextgetattributes.html on line 8

PtMultiTextGetAttributes()

Get the attributes of a PtMultiText widget

Synopsis:

PtMultiTextAttributes_t *
     PtMultiTextGetAttributes( 
         PtWidget_t *widget,
         int char_offset,
         PtMultiTextAttributes_t *attributes,
         int *start,
         int *end );

Description:

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.

Returns:

A pointer to the provided PtMultiTextAttributes_t structure, or NULL if the specified widget is NULL or isn't a PtMultiText widget.

Examples:

/* 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;
}

Classification:

Photon

Safety:
Interrupt handler No
Signal handler No
Thread No

See also:

PtMultiTextCreateAttributes(), PtTextGetSelection(), PtTextModifyText(), PtTextSetSelection(), PtMultiTextAttributes_t


Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/photon/widget_ref/pt/ptmultitextgetattributes.html on line 204

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/photon/widget_ref/pt/ptmultitextgetattributes.html on line 204