Prima
view release on metacpan or search on metacpan
class/Application.c view on Meta::CPAN
#include "apricot.h"
#include "Timer.h"
#include "Window.h"
#include "Image.h"
#include "Application.h"
#include <Application.inc>
#ifdef __cplusplus
extern "C" {
#endif
#undef my
#define inherited CWidget->
#define my ((( PApplication) self)-> self)
#define var (( PApplication) self)
static void Application_HintTimer_handle_event( Handle, PEvent);
void
Application_init( Handle self, HV * profile)
{
dPROFILE;
int hintPause = pget_i( hintPause);
Color hintColor = pget_i( hintColor), hintBackColor = pget_i( hintBackColor);
SV * hintFont = pget_sv( hintFont);
SV * sv;
char * hintClass = pget_c( hintClass);
if ( prima_guts.application != NULL_HANDLE)
croak( "Attempt to create more than one application instance");
opt_set(optSystemDrawable);
CDrawable-> init( self, profile);
list_create( &var-> widgets, 16, 16);
list_create( &var-> modalHorizons, 0, 8);
prima_guts.application = self;
if ( !apc_application_create( self))
croak( "Error creating application");
/* Widget init */
SvHV_Font( pget_sv( font), &Font_buffer, "Application::init");
my-> set_font( self, Font_buffer);
SvHV_Font( pget_sv( popupFont), &Font_buffer, "Application::init");
my-> set_popup_font( self, Font_buffer);
{
AV * av = ( AV *) SvRV( pget_sv( designScale));
SV ** holder = av_fetch( av, 0, 0);
if ( holder)
var-> designScale. x = SvNV( *holder);
else
warn("Array panic on 'designScale'");
holder = av_fetch( av, 1, 0);
if ( holder)
var-> designScale. y = SvNV( *holder);
else
warn("Array panic on 'designScale'");
pdelete( designScale);
}
var-> text = newSVpv("", 0);
var-> hint = newSVpv("", 0);
opt_set( optModalHorizon);
/* store extra info */
{
HV * hv = ( HV *) SvRV( var-> mate);
(void) hv_store( hv, "PrinterClass", 12, newSVpv( pget_c( printerClass), 0), 0);
(void) hv_store( hv, "PrinterModule", 13, newSVpv( pget_c( printerModule), 0), 0);
(void) hv_store( hv, "HelpClass", 9, newSVpv( pget_c( helpClass), 0), 0);
(void) hv_store( hv, "HelpModule", 10, newSVpv( pget_c( helpModule), 0), 0);
}
{
HV * profile = newHV();
static Timer_vmt HintTimerVmt;
pset_H( owner, self);
pset_i( timeout, hintPause);
pset_c( name, "HintTimer");
var-> hintTimer = create_instance( "Prima::Timer");
protect_object( var-> hintTimer);
hv_clear( profile);
memcpy( &HintTimerVmt, CTimer, sizeof( HintTimerVmt));
HintTimerVmt. handle_event = Application_HintTimer_handle_event;
(( PTimer) var-> hintTimer)-> self = &HintTimerVmt;
pset_H( owner, self);
pset_i( color, hintColor);
pset_i( backColor, hintBackColor);
pset_i( visible, 0);
pset_i( selectable, 0);
pset_i( showHint, 0);
pset_c( name, "HintWidget");
pset_sv( font, hintFont);
var-> hintWidget = create_instance( hintClass);
protect_object( var-> hintWidget);
sv_free(( SV *) profile);
}
if ( SvOK( sv = pget_sv( accelItems)))
my-> set_accelItems( self, sv);
if ( SvOK( sv = pget_sv( popupItems)))
my-> set_popupItems( self, sv);
pdelete( accelTable);
pdelete( accelItems);
pdelete( popupItems);
my-> set( self, profile);
CORE_INIT_TRANSIENT(Application);
}
void
Application_done( Handle self)
{
if ( self != prima_guts.application) return;
unprotect_object( var-> hintTimer);
unprotect_object( var-> hintWidget);
list_destroy( &var-> modalHorizons);
list_destroy( &var-> widgets);
if ( var-> text ) SvREFCNT_dec( var-> text);
if ( var-> hint ) SvREFCNT_dec( var-> hint);
free( var-> helpContext);
var-> accelTable = var-> hintWidget = var-> hintTimer = NULL_HANDLE;
var-> helpContext = NULL;
var-> hint = var-> text = NULL;
apc_application_destroy( self);
CDrawable-> done( self);
prima_guts.application = NULL_HANDLE;
}
static Bool
kill_all_objects( Handle self, Handle child, void * dummy)
{
Object_destroy( child);
return false;
}
void
Application_cleanup( Handle self)
{
int i;
for ( i = 0; i < var-> widgets. count; i++)
Object_destroy( var-> widgets. items[i]);
if ( var-> icon)
my-> detach( self, var-> icon, true);
var-> icon = NULL_HANDLE;
my-> first_that_component( self, 0, (void*)kill_all_objects, NULL);
CDrawable-> cleanup( self);
}
void
Application_set( Handle self, HV * profile)
{
pdelete( bottom);
pdelete( buffered);
pdelete( capture);
pdelete( centered);
pdelete( clipOwner);
pdelete( enabled);
pdelete( focused);
class/Application.c view on Meta::CPAN
return from;
from = PWidget( from)-> owner;
}
return prima_guts.application;
}
Handle
Application_get_image( Handle self, int x, int y, int xLen, int yLen)
{
HV * profile;
Handle i;
Bool ret;
Point sz;
if ( var-> stage > csFrozen) return NULL_HANDLE;
if ( x < 0 || y < 0 || xLen <= 0 || yLen <= 0) return NULL_HANDLE;
sz = apc_application_get_size( self);
if ( x + xLen > sz. x) xLen = sz. x - x;
if ( y + yLen > sz. y) yLen = sz. y - y;
if ( x >= sz. x || y >= sz. y || xLen <= 0 || yLen <= 0) return NULL_HANDLE;
profile = newHV();
i = Object_create( "Prima::Image", profile);
sv_free(( SV *) profile);
ret = apc_application_get_bitmap( self, i, x, y, xLen, yLen);
--SvREFCNT( SvRV((( PAnyObject) i)-> mate));
return ret ? i : NULL_HANDLE;
}
/*
* Cannot return NULL_HANDLE.
*/
Handle
Application_map_focus( Handle self, Handle from)
{
Handle topFrame = my-> top_frame( self, from);
Handle topShared;
if ( var-> topExclModal)
return ( topFrame == var-> topExclModal) ? from : var-> topExclModal;
if ( !var-> topSharedModal && var-> modalHorizons. count == 0)
return from; /* return from if no shared modals active */
if ( topFrame == self) {
if ( !var-> topSharedModal) return from;
topShared = var-> topSharedModal;
} else {
Handle horizon =
( !CWindow( topFrame)-> get_modalHorizon( topFrame)) ?
CWindow( topFrame)-> get_horizon( topFrame) : topFrame;
if ( horizon == self)
topShared = var-> topSharedModal;
else
topShared = PWindow( horizon)-> topSharedModal;
}
return ( !topShared || ( topShared == topFrame)) ? from : topShared;
}
static Handle
popup_win( Handle xTop)
{
PWindow_vmt top = CWindow( xTop);
if ( !top-> get_visible( xTop))
top-> set_visible( xTop, 1);
if ( top-> get_windowState( xTop) == wsMinimized)
top-> set_windowState( xTop, wsNormal);
top-> set_selected( xTop, 1);
return xTop;
}
Handle
Application_popup_modal( Handle self)
{
Handle ha = apc_window_get_active();
Handle xTop;
if ( var-> topExclModal) {
/* checking exclusive modal chain */
xTop = ( !ha || ( PWindow(ha)->modal == 0)) ? var-> exclModal : ha;
while ( xTop) {
if ( PWindow(xTop)-> nextExclModal) {
CWindow(xTop)-> bring_to_front( xTop);
xTop = PWindow(xTop)-> nextExclModal;
} else {
return popup_win( xTop);
}
}
} else {
if ( !var-> topSharedModal && var-> modalHorizons. count == 0)
return NULL_HANDLE; /* return from if no shared modals active */
/* checking shared modal chains */
if ( ha) {
xTop = ( PWindow(ha)->modal == 0) ? CWindow(ha)->get_horizon(ha) : ha;
if ( xTop == prima_guts.application) xTop = var-> sharedModal;
} else
xTop = var-> sharedModal ? var-> sharedModal : var-> modalHorizons. items[ 0];
while ( xTop) {
if ( PWindow(xTop)-> nextSharedModal) {
CWindow(xTop)-> bring_to_front( xTop);
xTop = PWindow(xTop)-> nextSharedModal;
} else {
return popup_win( xTop);
}
}
}
return NULL_HANDLE;
}
Bool
Application_pointerVisible( Handle self, Bool set, Bool pointerVisible)
{
if ( !set)
return apc_pointer_get_visible( self);
return apc_pointer_set_visible( self, pointerVisible);
}
Point
Application_size( Handle self, Bool set, Point size)
{
if ( set) return size;
return apc_application_get_size( self);
}
Point
Application_origin( Handle self, Bool set, Point origin)
{
Point p = { 0, 0};
return p;
}
Bool
Application_modalHorizon( Handle self, Bool set, Bool modalHorizon)
{
return true;
}
Bool
Application_textDirection( Handle self, Bool set, Bool textDirection)
{
if ( !set ) return var->textDirection;
return var-> textDirection = textDirection;
}
#define UISCALING_STEP 4
double
Application_uiScaling( Handle self, Bool set, double uiScaling)
{
if ( !set ) return var->uiScaling;
if ( uiScaling < 0.00001 ) {
Point res = my-> get_resolution(self);
uiScaling = (double)((int)((double) res.x/ (96.0/UISCALING_STEP) + 0.5)) / UISCALING_STEP; /* 96-143 = 1.5, 144-191 = 1.5 etc */
if ( uiScaling < 0.25 ) uiScaling = 0.25;
}
return var-> uiScaling = uiScaling;
}
Bool
Application_wantUnicodeInput( Handle self, Bool set, Bool want_ui)
{
if ( !set) return var-> wantUnicodeInput;
if ( apc_sys_get_value( svCanUTF8_Input))
( run in 1.296 second using v1.01-cache-2.11-cpan-364913b4093 )