Subversion Repositories filter_foundry

Rev

Rev 193 | Rev 268 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /*
  2.         This file is part of a common library
  3.     Copyright (C) 1990-2006 Toby Thain, toby@telegraphics.com.au
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by  
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License  
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18. */
  19.  
  20. #include "calc_std_state.h"
  21. #include "wind.h"
  22.  
  23. void set_std_state(WindowPtr w,Rect *r){
  24.         if(ZOOMABLE(w))
  25.                 (*(WStateDataHandle)((WindowPeek)w)->dataHandle)->stdState = *r;
  26. }
  27. void std_user_state(WindowPtr w){
  28.         WStateDataHandle h = (WStateDataHandle)((WindowPeek)w)->dataHandle; // ppcc wants cast
  29.         if(ZOOMABLE(w))
  30.                 (*h)->userState = (*h)->stdState;
  31. }
  32.  
  33. void calc_std_state(WindowPtr w,Boolean force_default,Boolean stagger,Rect *s){
  34.         short i,new_left,new_top,h_offset,v_offset;
  35.         Rect d,wr,sr,r;
  36.         Boolean spot_taken,too_wide,too_high;
  37.         WindowPeek peek;
  38.         Point size;
  39.  
  40. /* As per Human Interface Note 7,
  41.  * recalculate standard state starting from user state,
  42.  * so that top-left corner of window only moves if necessary.
  43.  */
  44.  
  45. /* "display each additional window on the screen that
  46.  *  contains the largest portion of the frontmost window" */
  47.  
  48.         size = natural_size(w);
  49.         d = FrontWindow() ? dominant_device_rect(FrontWindow()) : main_device_rect();
  50.         global_wind_rect(w,&wr);
  51.         get_struc_bbox(w,&sr);
  52.         InsetRect(&d,2,2);
  53.         d.left += wr.left - sr.left;
  54.         d.top += wr.top - sr.top;
  55.         d.right += wr.right - sr.right;
  56.         d.bottom += wr.bottom - sr.bottom;
  57.  
  58.         h_offset = v_offset = 0;
  59.         do{
  60.                 *s = d;
  61.                 new_left = (force_default || wr.left<s->left ? s->left : wr.left) + h_offset;
  62.                 new_top = (force_default || wr.top<s->top ? s->top : wr.top) + v_offset;
  63.                 if(too_wide = (i=new_left+size.h)>s->right)
  64.                         if((i=s->right-size.h)>s->left)
  65.                                 s->left = i; // move window left to expose entire content
  66.                         else{ // natural size is wider than screen
  67.                                 short new_width = width_filter(w,i = s->right - s->left);
  68.                                 new_width>i ? (s->right=s->left+new_width) : (s->left=s->right-new_width);
  69.                         }
  70.                 else{
  71.                         s->left = new_left;
  72.                         s->right = i;
  73.                 }
  74.                 if(too_high = (i=new_top+size.v)>s->bottom)
  75.                         if((i=s->bottom-size.v)>s->top)
  76.                                 s->top = i; // move window up to expose entire content
  77.                         else{ // natural size is higher than screen
  78.                                 short new_height = height_filter(w,i = s->bottom - s->top);
  79.                                 new_height>i ? (s->bottom=s->top+new_height) : (s->top=s->bottom-new_height);
  80.                         }
  81.                 else{
  82.                         s->top = new_top;
  83.                         s->bottom = i;
  84.                 }
  85.  
  86.                 spot_taken = false;
  87.                 if(stagger && !(too_wide||too_high))
  88.                         for(peek = (WindowPeek)FrontWindow(); peek; peek = peek->nextWindow)
  89.                                 if(peek->visible){
  90.                                         global_wind_rect((WindowPtr)peek,&r);
  91.                                         if( abs(s->left-r.left) + abs(s->top-r.top) < STAGGER_SLOP ){
  92.                                                 spot_taken = true;
  93.                                                 h_offset += STAGGER_H;
  94.                                                 v_offset += STAGGER_V;
  95.                                                 break;
  96.                                         }
  97.                                 }
  98.         }while(spot_taken);
  99. }
  100.  
  101. void zoom_to_std_state(WindowPtr w,Boolean force_default,Boolean stagger){ Rect r;
  102.         calc_std_state(w,force_default,stagger,&r);
  103.         if(ZOOMABLE(w)){
  104.                 set_std_state(w,&r);
  105.                 SetPort(w);
  106.                 ZoomWindow(w,inZoomOut,false);
  107.         }else{
  108.                 MoveWindow(w,r.left,r.top,false);
  109.                 SizeWindow(w,r.right-r.left,r.bottom-r.top,true/*???*/);
  110.         }
  111. }
  112.