home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / DevTools / eText5 / Source / Kludges.subproj / DPFontPanel.m < prev    next >
Encoding:
Text File  |  1995-01-25  |  5.9 KB  |  192 lines

  1. /* This file has been modified by Rohit Khare, 10/31/94 */
  2. /*
  3.  * Copyright (c) 1992 Athena Design, Inc. and David Pollak  
  4.  *
  5.  *            ALL RIGHTS RESERVED       
  6.  * 
  7.  *
  8.  * Redistribution and use in source and binary forms, with or without
  9.  * modification, are permitted provided that the following conditions
  10.  * are met:
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  * 2. Redistributions in binary form must reproduce the above copyright
  14.  *    notice, this list of conditions and the following disclaimer in the
  15.  *    documentation and/or other materials provided with the distribution.
  16.  * 3. Neither the name of the company (Athena Design) nor the names of its 
  17.  *    employees may be used to endorse or promote products derived from this 
  18.  *    software without specific prior written permission.
  19.  *
  20.  * THIS SOFTWARE IS PROVIDED BY ATHENA DESIGN ``AS IS'' AND
  21.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23.  * ARE DISCLAIMED.  IN NO EVENT SHALL ATHENA DESIGN BE LIABLE
  24.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  26.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  28.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  29.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30.  * SUCH DAMAGE.
  31.  */
  32.  
  33. #import "DPFontPanel.h"
  34. #import "FontWell.h"
  35. #import "ENXCP.h"
  36.  
  37. #import <appkit/Window.h>
  38. #import <appkit/View.h>
  39. #import <appkit/Application.h>
  40. #import <libc.h>
  41. #import <appkit/FontManager.h>
  42. #import <appkit/NXBrowser.h>
  43. #import <appkit/NXBrowserCell.h>
  44. #import <appkit/TextField.h>
  45. #import <appkit/Font.h>
  46. #import <appkit/publicWraps.h>
  47. #import <objc/List.h>
  48. #import <dpsclient/psops.h>
  49. #import <dpsclient/wraps.h>
  50. #import <appkit/Panel.h>
  51.  
  52.  
  53. static id doHitTest(id rootView, const NXPoint *aPoint)
  54. {
  55.     id subviews, subview;
  56.     int i;
  57.     NXPoint point;
  58.     NXRect rect;
  59.  
  60.     point = *aPoint;
  61.     [rootView convertPoint:&point fromView:nil];
  62.     [rootView getBounds:&rect];
  63.     if (NXMouseInRect(&point, &rect, [rootView isFlipped])) {
  64.     subviews = [rootView subviews];
  65.     for (i = [subviews count] - 1; i >= 0; i--) {
  66.         subview = [subviews objectAt:i]; 
  67.         if ((subview = doHitTest(subview, aPoint)))
  68.         return subview;
  69.     }
  70.     return rootView;
  71.     } else
  72.         return nil;
  73. }
  74.  
  75. @implementation DPFontPanel
  76.  
  77. + new
  78. {
  79.     DPFontPanel *dfp;
  80.     id tid,tid2;
  81.     NXRect re;
  82.         
  83.     dfp = [super new];
  84.     tid2 = dfp -> preview;
  85.     //tid2 = dfp -> current;
  86.     [tid2 getBounds:&re];
  87.     tid = [[FontWell alloc] initFrame:&re];
  88.     [tid setAutosizing:NX_WIDTHSIZABLE | NX_HEIGHTSIZABLE];
  89.     [tid2 setAutoresizeSubviews:YES];
  90.     [tid setFontObj:&(dfp -> selFont)];
  91.     [tid setLastPreview:&(dfp -> lastPreview)];
  92.     [tid setAction:@selector(changeFont:)];
  93.     [tid setAction:NULL];
  94.     [tid setTarget:NULL];
  95.     
  96.     [tid2 addSubview:tid];
  97.     [tid2 display];
  98.     return dfp;
  99. }
  100.  
  101. + dragFont:font withEvent:(NXEvent *)ev fromView:view
  102. {
  103.     id        imageWindow,localWindow,tv,myView;
  104.     NXRect    windowRect,rect;
  105.     NXPoint    mouseDownPoint,currentPoint,upPoint;
  106.     int        mask;
  107.     unsigned int hitWindow,wNum;
  108.     float    dx,dy;
  109.  
  110.     if ([font matrix] != NX_IDENTITYMATRIX)
  111.         font = [Font newFont:[font name] size:[font pointSize] matrix:NX_IDENTITYMATRIX];
  112.  
  113.     [[view window] convertBaseToScreen:&(ev -> location)];
  114.     // added upPoint initialization to cure dps bug if there was a quick click and no drag
  115.     upPoint = mouseDownPoint = ev->location;
  116.     
  117.     windowRect.origin = ev -> location;
  118.     windowRect.size.width = windowRect.size.height = 16.0;
  119.     windowRect.origin.x -= 8.0;
  120.     windowRect.origin.y -= 8.0;
  121.     
  122.   /* create an image window in the same location as our image */
  123.     imageWindow = [[Window alloc] initContent:&windowRect
  124.                   style:NX_PLAINSTYLE
  125.                   backing:NX_BUFFERED
  126.                   buttonMask:0
  127.                   defer:YES];
  128.     
  129.               
  130.     [imageWindow orderFront:NULL];
  131.     PSsetwindowlevel(NX_MAINMENULEVEL + 5,[imageWindow windowNum]);
  132.     [imageWindow orderWindow:NX_ABOVE relativeTo:0];
  133.  
  134.     rect.origin.x = rect.origin.y = 0.0;
  135.     rect.size.height = rect.size.width = 16.0;
  136.     myView = [[View alloc] initFrame:&rect];
  137.     [[imageWindow setContentView:myView]free];
  138.     [myView lockFocus];
  139.     NXSetColor(NX_COLORWHITE);
  140.     PSrectfill(0.,0.,16.,16.);
  141.     NXSetColor(NX_COLORBLACK);
  142.     PSrectstroke(0.,1.,15.,15.);
  143.     PSmoveto(2,3);
  144.     [font set];
  145.     PSshow("F");
  146.     PSflush();
  147.     [myView unlockFocus];
  148.     [imageWindow flushWindow];
  149.     NXPing();
  150.     
  151.     dx = (NX_X(&windowRect) - mouseDownPoint.x);
  152.     dy = (NX_Y(&windowRect) - mouseDownPoint.y);
  153.   /* get mouse-dragged events also (and save original mask for later) */
  154.     mask = [[view window] addToEventMask:NX_MOUSEDRAGGEDMASK];
  155.     
  156.     do {
  157.       /* wait for the next important event */
  158.         ev = [NXApp getNextEvent:NX_MOUSEDRAGGEDMASK|NX_MOUSEUPMASK];
  159.       
  160.           /* move the window to its new position */
  161.         [[view window] convertBaseToScreen:&(ev -> location)];
  162.         if (ev->type == NX_MOUSEDRAGGED) upPoint = ev -> location;
  163.         currentPoint = ev->location;
  164.         [imageWindow moveTo:(currentPoint.x + dx) :(currentPoint.y + dy)];
  165.             
  166.           /* convert the current mouse location to screen coordinates */
  167.       
  168.       
  169.     } while (ev->type == NX_MOUSEDRAGGED);
  170.     
  171.   /* no longer need mouse dragged events, so reset the event mask */
  172.     [[view window] setEventMask:mask];
  173.  
  174.     [[imageWindow orderOut:self] free];
  175.     
  176.     PSWfindownedwindow(upPoint.x,upPoint.y,&mouseDownPoint.x,&mouseDownPoint.y,&hitWindow);
  177.  
  178.     if (hitWindow) {
  179.         NXConvertGlobalToWinNum(hitWindow,&wNum);
  180.         localWindow = [NXApp findWindow:wNum];
  181.         tv = doHitTest([localWindow contentView], &mouseDownPoint);
  182.         if (tv != view && [tv respondsTo:@selector(acceptFont:atPoint:)]) {
  183.             [tv acceptFont:font atPoint:&mouseDownPoint];
  184.             [[tv window] makeKeyWindow];
  185.             }
  186.     }    
  187.     return self;
  188. }
  189.  
  190. - free {return self;}
  191. @end
  192.