/* Copyright 1996 Acorn Computers Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/************************************************************************/
/* � Acorn Computers Ltd, 1992.                                         */
/*                                                                      */
/* This file forms part of an unsupported source release of RISC_OSLib. */
/*                                                                      */
/* It may be freely used to create executable images for saleable       */
/* products but cannot be sold in source form or as an object library   */
/* without the prior written consent of Acorn Computers Ltd.            */
/*                                                                      */
/* If this file is re-distributed (even if modified) it should retain   */
/* this copyright notice.                                               */
/*                                                                      */
/************************************************************************/

/* Title: c.Magnify
 * Purpose: display and respond to a magnifier box
 * History: IDJ: 06-Feb-92: prepared for source release
 *
 */


#include "os.h"
#include "wimp.h"
#include "wimpt.h"
#include "dbox.h"
#include "magnify.h"
#include "help.h"

void magnify_select(int *mul, int *div, int maxmul, int maxdiv,
                      void (*proc)(void *), void *phandle)
{
 dbox d;
 int wot;

 d = dbox_new("magnifier");
 if (!d) return;
 dbox_raw_eventhandler(d, help_dboxrawevents, "MAGNIFIER");
 dbox_setnumeric(d, 0, *mul<1?1:*mul) ;
 dbox_setnumeric(d, 1, *div<1?1:*div) ;
 dbox_show(d) ;

 while ((wot = dbox_fillin_fixedcaret(d)) != dbox_CLOSE)
 {
  wimp_mousestr ratty ;
  wimpt_noerr(wimp_get_point_info(&ratty)) ;

  *mul = dbox_getnumeric(d, 0) ;
  *div = dbox_getnumeric(d, 1) ;

  if (ratty.bbits & 1) wot = wot^1 ;    /* adjust goes the other way */

  switch (wot)
  {
   case 2: ++*mul ; break ;
   case 3: --*mul ; break ;
   case 4: ++*div ; break ;
   case 5: --*div ; break ;
  }
  if (*mul > maxmul) *mul = maxmul ; if (*mul < 1) *mul = 1 ;
  if (*div > maxdiv) *div = maxdiv ; if (*div < 1) *div = 1 ;
  dbox_setnumeric(d, 0, *mul) ;
  dbox_setnumeric(d, 1, *div) ;

  if (proc) proc(phandle) ;
 }

 dbox_dispose(&d) ;
}

/* end */