/* 
Copyright (c) 1991-2000 UserLand Software, Inc. 

Permission is hereby granted, free of charge, to any person obtaining a 
copy of this software and associated documentation files (the 
"Software"), to deal in the Software without restriction, including 
without limitation the rights to use, copy, modify, merge, publish, 
distribute, sublicense, and/or sell copies of the Software, and to 
permit persons to whom the Software is furnished to do so, subject to the 
following conditions: 

The above copyright notice and this permission notice shall be 
included in all copies or substantial portions of the Software. 

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
*/ 


#include "iowacore.h"
#include <applet.h>
#include "appletquickdraw.h"
#include "iowaobject.h"
#include "iowainfowindow.h"


void madechanges (void) {
	
	setappwindowmadechanges (app.appwindow);
	
	resetinfowindows (); /*DW 12/4/93*/
		
	iowavalidate ((**iowadata).runmode);
	} /*madechanges*/
	
	
void selectiondirty (void) {
	
	if (app.appwindow != nil) {
	
		(**app.appwindow).selectioninfo.fldirty = true;
		}
	
	resetinfowindows (); /*DW 12/4/93*/
		
	iowavalidate ((**iowadata).runmode);
	} /*selectiondirty*/ 
	

hdleditrecord getanyactiveeditrecord (void) {
	
	/*
	11/7/92 DW: I agree this is a klooge. but it makes a bunch of stuff work.
	
	a frontend for getactiveeditrecord, if there is no active text object, then
	we check in the status bar for an active edit buffer and return that. it makes
	it possible for the same code to implement cut/copy/paste in either an object
	being edited, or in the name/script edit boxes.
	*/

	hdlcard hc = iowadata;
	hdlobject h;
	
	if (hc == nil)
		return (nil);
		
	h = (**hc).activetextobject;
	
	if (h != nil)	
		return ((hdleditrecord) (**h).objecteditrecord);
		
	/*check in the status bar*/ {
	
		hdleditinfo he = (hdleditinfo) (**hc).refcon;

		if ((**he).flstatusbaredit) 
			return ((**he).heditbuffer);
		}
	
	return (nil);
	} /*getanyactiveeditrecord*/
	
	
static void getnubrect (hdlobject x, Rect *nubrect) {
	
	Rect r;
	
	getobjectrect (x, &r);
	
	r.top = r.bottom - nubsize;
	
	r.left = r.right - nubsize;
	
	*nubrect = r;
	} /*getnubrect*/
	
	
void drawselectionframe (hdlobject h, Rect r, boolean flframe) {
	
	Rect rwhole;
	
	pushforecolor (&(**h).objectframecolor);
	
	if (flframe)
		FrameRect (&r);
		
	rwhole = r;
		
	r.top = r.bottom - nubsize;
	
	if (r.top < rwhole.top) /*1.0b15*/
		r.top = rwhole.top;
	
	r.left = r.right - nubsize;

	if (r.left < rwhole.left) /*1.0b15*/
		r.left = rwhole.left;
	
	FillRect (&r, &quickdrawglobal (black)); 

	popforecolor ();
	} /*drawselectionframe*/
	
	
boolean pointinnub (hdlobject x, Point pt) {
	
	Rect r;
	
	getnubrect (x, &r);
	
	r.top--; r.left--; /*1.0b15, doug suggests making it a little easier to resize objects*/
	
	return (PtInRect (pt, &r));
	} /*pointinnub*/
	
	
void invalnub (hdlobject x) {

	Rect r;
	
	getnubrect (x, &r);
	
	iowainvalrect (&r);
	} /*invalnub*/
	

void zapcardwindow (void) {
	
	hdlappwindow ha = app.appwindow;
	Rect r;
	
	r = (**ha).contentrect;
	
	r.top += (**ha).scrollorigin.v;
	
	r.left += (**ha).scrollorigin.h;
	
	iowainvalrect (&r);
	} /*zapcardwindow*/
	

boolean setcardsize (short rightborder, short bottomborder) {
	
	hdlcard hc = iowadata;
	
	(**hc).rightborder = rightborder;
	
	(**hc).bottomborder = bottomborder;
	
	zapcardwindow ();
	
	return (true);
	} /*setcardsize*/