www.pudn.com > helpview.zip > Copy.c, change:1997-10-15,size:8574b


/* 
  
Copyright 1997 Willows Software, Inc.  
 
This library is free software; you can redistribute it and/or 
modify it under the terms of the GNU Library General Public License as 
published by the Free Software Foundation; either version 2 of the 
License, or (at your option) any later version. 
 
This library is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without even the implied warranty of 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
Library General Public License for more details. 
 
You should have received a copy of the GNU Library General Public 
License along with this library; see the file COPYING.LIB.  If 
not, write to the Free Software Foundation, Inc., 675 Mass Ave, 
Cambridge, MA 02139, USA. 
 
*/ 
 
/************************************************************************* 
* 
*   DIALOGS.C 
*   Copy Text to Clipboard      
* 
*	Author: Paul E. Kissel 
* 
**************************************************************************/ 
 
/*********************************** 
** 
**  System Includes 
** 
***********************************/ 
 
/*********************************** 
** 
**  App. Includes 
** 
***********************************/ 
#include "copy.h" 
#include "inifile.h" 
#include "globals.h" 
#include "wnddata.h" 
#include "wndpos.h" 
#include "twhlprc.h" 
#include "display.h" 
 
 
/*********************************** 
** 
**  Private File Defines 
** 
***********************************/ 
 
 
/*********************************** 
** 
**  Private Function Prototypes 
** 
***********************************/ 
 
BOOL CALLBACK CopyDlgProc( HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam ); 
static void PositionControls( HWND hWnd ); 
 
 
/*********************************************************************************** 
** 
**                              Shared Functions 
** 
************************************************************************************/ 
 
 
/********************************************************** 
**   
**  Displays the Copy dialog box. 
**   
***********************************************************/ 
BOOL ShowCopyDialogBox( HWND hDataWnd, HWND hTopicWnd ) 
{ 
  BOOL bDlgAlreadyDisplayed; 
   
  /* Is the Copy dialog box already displayed. */ 
  bDlgAlreadyDisplayed = (BOOL) WndData( hDataWnd, WDM_GETCOPYDLGDISPLAYED, 0, NULL ); 
              
  /* The Copy dialog box is already displayed. */ 
  if( bDlgAlreadyDisplayed == TRUE ) 
  { 
    /* Failed. */ 
    return( FALSE ); 
  } 
 
 
  /* The Copy dialog box is being displayed. */ 
  WndData( hDataWnd, WDM_SETCOPYDLGDISPLAYED, (DWORD) TRUE, NULL ); 
              
  /* Show Copy dialog. */ 
  DialogBoxParam( GetLibInst(), "DLG_COPYTEXT", hTopicWnd, CopyDlgProc, (LPARAM) (HWND *) &hTopicWnd ); 
 
  /* The Copy dialog box is not being displayed. */ 
  WndData( hDataWnd, WDM_SETCOPYDLGDISPLAYED, (DWORD) FALSE, NULL ); 
              
  /* Success. */ 
  return( TRUE ); 
} 
 
 
 
/*********************************************************************************** 
** 
**                              Private Functions 
** 
************************************************************************************/ 
 
/********************************* 
** 
**  "DLG_COPYTEXT" dialog box procedure. 
** 
**********************************/ 
BOOL CALLBACK CopyDlgProc( HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam ) 
{ 
  WINDOWPLACEMENT WndPlace; 
  BOOL bSettingFound; 
   
  HGLOBAL hTopicText; 
  char * TopicTextPtr; 
   
  HWND * hTopicWindowPtr; 
 
   
  switch( wMsg )  
  { 
    /* Window initialization. */ 
    case WM_INITDIALOG: 
    {   
      /* Get last saved size and position. */ 
      bSettingFound = ReadLastCopyWndPos( &WndPlace ); 
 
      /* If setting found. */ 
      if( bSettingFound == TRUE ) 
      { 
        /* If should be not maximized. */ 
        if( WndPlace.showCmd != SW_SHOWMAXIMIZED ) 
        { 
          /* Convert virtual position to physical coords. */ 
          VirtualPosToScrnPos( hWnd, &(WndPlace).rcNormalPosition ); 
             
          /* Size and position the window. */ 
          SetWindowPos( hWnd, NULL,  
                        WndPlace.rcNormalPosition.left,  
                        WndPlace.rcNormalPosition.top,  
                        WndPlace.rcNormalPosition.right,  
                        WndPlace.rcNormalPosition.bottom, 
                        SWP_NOZORDER ); 
        } 
 
        /* If should be maximized. */ 
        else 
        { 
          ShowWindow ( hWnd, SW_SHOWMAXIMIZED ) ; 
        } 
 
        /* Position the controls in the window. */ 
        PositionControls( hWnd ); 
      } 
       
      /* Create buffer with topic's text. */ 
      hTopicWindowPtr = (HWND *) lParam; 
      hTopicText = GetTopicsText( *hTopicWindowPtr ); 
       
      /* If we got the topic text. */ 
      if( hTopicText != NULL ) 
      { 
        TopicTextPtr = (char *) GlobalLock( hTopicText ); 
        SendMessage( GetDlgItem( hWnd, IDC_TOPICTEXT ), WM_SETTEXT, 0,  
                     (LPARAM) (LPCSTR) TopicTextPtr ); 
        GlobalUnlock( hTopicText ); 
        GlobalFree( hTopicText ); 
      } 
 
      /* Use standard default control. */ 
      return( TRUE ); 
    } 
         
    case WM_SIZE: 
    { 
      /* Position the controls in the window. */ 
      PositionControls( hWnd ); 
       
      return( TRUE ); 
    } 
     
    case WM_COMMAND: 
    { 
      switch (wParam)  
      { 
        case IDOK:  
        { 
          if( HIWORD(lParam) == BN_CLICKED ) 
          { 
            /* Copy text to the clipboard. */ 
            SendMessage( GetDlgItem( hWnd, IDC_TOPICTEXT ), WM_COPY, 0, 0L );  
 
            /* Save size and position info. */       
            MakeWndVirtualPos( hWnd, &WndPlace ); 
            WriteLastCopyWndPos( &WndPlace ); 
 
            EndDialog( hWnd, IDOK ); 
          } 
           
          return( TRUE ); 
        } 
 
        case IDCANCEL: 
        { 
          if( HIWORD(lParam) == BN_CLICKED ) 
          { 
            /* Save size and position info. */       
            MakeWndVirtualPos( hWnd, &WndPlace ); 
            WriteLastCopyWndPos( &WndPlace ); 
 
            EndDialog( hWnd, IDCANCEL ); 
          } 
           
          return( TRUE ); 
        } 
      } 
       
      return( TRUE ); 
    } 
  } 
 
  /* Return message processed result. */ 
  return( FALSE ); 
} 
 
 
static void PositionControls( HWND hWnd ) 
{ 
  RECT ClientRect; 
  RECT EditRect; 
  RECT ButtonRect; 
   
  int NewLeft; 
  int NewRight; 
  int NewBottom; 
   
     
  /* Get size of client. */ 
  GetClientRect( hWnd, &ClientRect ); 
 
  /* Get client position of edit control. */ 
  GetWindowRect( GetDlgItem( hWnd, IDC_TOPICTEXT ), &EditRect ); 
  MapWindowPoints( HWND_DESKTOP, hWnd, (POINT *) &EditRect, 2); 
   
  /**  
  *** STEP #1 - Position buttons. 
  **/ 
 
  /* Get position of OK button. */ 
  GetWindowRect( GetDlgItem( hWnd, IDOK ), &ButtonRect ); 
  MapWindowPoints( HWND_DESKTOP, hWnd, (POINT *) &ButtonRect, 2); 
 
  /*  
  ** Calc. left edge buttons. 
  ** Right edge of window - left border - Width of button. 
  ** 
  ** Both buttons have same width and height. 
  */ 
  NewLeft = ClientRect.right - EditRect.left - (ButtonRect.right - ButtonRect.left); 
 
  /* Set position of OK button. */ 
  SetWindowPos( GetDlgItem( hWnd, IDOK ), NULL,  
                NewLeft,  
                ButtonRect.top,  
                ButtonRect.right - ButtonRect.left,  
                ButtonRect.bottom - ButtonRect.top, 
                SWP_NOZORDER ); 
 
  /* Get position of OK button. */ 
  GetWindowRect( GetDlgItem( hWnd, IDCANCEL ), &ButtonRect ); 
  MapWindowPoints( HWND_DESKTOP, hWnd, (POINT *) &ButtonRect, 2); 
 
  /* Set position of CANCEL button. */ 
  SetWindowPos( GetDlgItem( hWnd, IDCANCEL ), NULL,  
                NewLeft,  
                ButtonRect.top,  
                ButtonRect.right - ButtonRect.left,  
                ButtonRect.bottom - ButtonRect.top, 
                SWP_NOZORDER ); 
 
  /* Calc. right edge of edit control. */ 
  NewRight = NewLeft - EditRect.left; 
 
  /* Calc. bottom edge of edit control. */ 
  NewBottom = ClientRect.bottom - EditRect.left; 
   
  /* Set position of edit control. */ 
  SetWindowPos( GetDlgItem( hWnd, IDC_TOPICTEXT ), NULL,  
                EditRect.left,  
                EditRect.top,  
                NewRight - EditRect.left,  
                NewBottom - EditRect.top, 
                SWP_NOZORDER ); 
}