/* 
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 "appletinternal.h"
#include "appletmsg.h"


#define messagefont kFontIDGeneva
#define messagesize 9
#define messagestyle 0



void appsetmessagerect (hdlappwindow appwindow) {
	
	Rect r;
		
	if (app.hasmessagearea) {
	
		Rect rwindow = (*(**appwindow).macwindow).portRect;
		
		r.bottom = rwindow.bottom;
		
		r.left = rwindow.left;
		
		r.top = r.bottom - getscrollbarwidth () + 1;
		
		r.right = r.left + ((rwindow.right - rwindow.left) / 2);
		}
	else
		zerorect (&r);
	
	(**appwindow).messagerect = r;
	} /*appsetmessagerect*/
	

void appdrawmessage (hdlappwindow appwindow) {
	
	if (app.hasmessagearea) {
		
		hdlappwindow ha = appwindow;
		WindowPtr w = (**ha).macwindow;
		Rect r = (**ha).messagerect;
		Rect rerase, rtext;
		bigstring bs;
		boolean flbitmap = false;
		
		pushmacport (w);
		
		/*flbitmap = openbitmap (r, w);*/
		
		pushclip (r);
		
		rerase = r; rerase.top++; rerase.right--; eraserect (rerase);
		
		pushforecolor (&blackcolor);
		
		MoveTo (r.left, r.top); LineTo (r.right, r.top);
		
		popforecolor ();
		
		texthandletostring ((**ha).hmessage, bs);
	
		pushstyle (messagefont, messagesize, messagestyle);
		
		rtext = r;
		
		InsetRect (&rtext, 1, 1);
	
		centerstring (rtext, bs);
	
		popstyle ();
		
		popclip ();
		
		if (flbitmap)
			closebitmap (w);
		
		popmacport ();
		}
	} /*appdrawmessage*/
	
	
void appsetmessage (hdlappwindow appwindow, bigstring bs) {
	
	hdlappwindow ha = appwindow;
	
	if (ha == nil)
		return;
		
	if (app.hasmessagearea) {
		
		Handle htext;
		
		/*8/29/94 DW: don't do anything if the message hasn't changed*/ {
			
			bigstring bscurrentmessage;
			
			texthandletostring ((**ha).hmessage, bscurrentmessage);
			
			if (equalstrings (bscurrentmessage, bs)) /*nothing to do*/
				return;
			}
	
		disposehandle ((**ha).hmessage);
		
		if (stringlength (bs) == 0)
			htext = nil;
		else
			newtexthandle (bs, &htext);
	
		(**ha).hmessage = htext;
	
		appdrawmessage (ha);
		}
	} /*appsetmessage*/
	
	
void appmessageclick (hdlappwindow appwindow) {
	
	if ((**appwindow).msgclickcallback != nil)
		(*(**appwindow).msgclickcallback) ();
	} /*appmessageclick*/