/* 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.
 */
/* > C.Magnify
 *
 *   Display and entry of magnification factors
 *   History:
 *            IDJ: 02-Jul-91: added help handler
 *
 *  Author: A.P. Thompson
 */

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

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 */