DRAFT1.C

Go to the documentation of this file.
00001 /* --
00002 OpenFX version 1.0 - Modelling, Animation and Rendering Package
00003 Copyright (C) 2000 OpenFX Development Team
00004 
00005 This program is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU General Public License
00007 as published by the Free Software Foundation; either version 2
00008 of the License, or (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with this program; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 
00019 You may contact the OpenFX development team via elecronic mail
00020 at core@openfx.org, or visit our website at http://openfx.org for
00021 further information and support details.
00022 -- */
00023 
00024 /* file DRAFT1.C */
00025 
00026 char szToolboxClass[]="SFX:DraftToolboxClass",
00027      szToolBtnClass[]="SFX:DraftToolBtnClass";
00028 
00029 typedef struct tagTOOL_CONTROL{
00030  int     idToolBtnUp,idToolBtnDown;
00031  HBITMAP hbmToolBtnUp,hbmToolBtnDown;
00032  int     Message,Help,Tip;
00033 } TOOL_CONTROL;
00034 
00035 #define TOOLBOXSTYLE  (WS_POPUP | WS_CLIPSIBLINGS | !WS_CAPTION | !WS_SYSMENU)
00036 
00037 static HWND CreateCommandPannel(TOOL_CONTROL aTC[],int n,char *title,
00038                                 int nc,int nr,int x,int y,int gap,HWND parent);
00039 static void DeleteCommandPannel(TOOL_CONTROL aTC[],int n);
00040 static void PannelDrawBitmap(HDC hDC,int tp,TOOL_CONTROL aT[],int type,
00041                              int ctool);
00042 static void PannelSelectTool(HWND hwnd, int *oldtool, int newtool);
00043 static void DoAddTooltip(HWND hwndOwner, HWND tipon, int resid);
00044 static HWND DoCreateTooltip(HWND hwndOwner);
00045 
00046 #define NO_MESSAGE -1
00047 #define NO_HELP    -1
00048 
00049 #define NTOOLS         7
00050 
00051 #define TOOLCOLUMNS    1
00052 #define TOOLROWS       7
00053 
00054 static HWND hwndDraftTools=NULL,hwnd_dtools,hwndTooltip=NULL;
00055 static int gCurDraftTool=-1;
00056 static int tool=0;
00057 static HINSTANCE ghinst_draft;
00058 
00059 static TOOL_CONTROL aTools[NTOOLS]={
00060   IDBM_DFT0U,IDBM_DFT0D,NULL,NULL,IDM_TP_0,NO_HELP,IDI_TIP_0,
00061   IDBM_DFT1U,IDBM_DFT1D,NULL,NULL,IDM_TP_1,NO_HELP,IDI_TIP_1,
00062   IDBM_DFT2U,IDBM_DFT2D,NULL,NULL,IDM_TP_2,NO_HELP,IDI_TIP_2,
00063   IDBM_DFT3U,IDBM_DFT3D,NULL,NULL,IDM_TP_3,NO_HELP,IDI_TIP_3,
00064   IDBM_DFT4U,IDBM_DFT4D,NULL,NULL,IDM_TP_4,NO_HELP,IDI_TIP_4,
00065   IDBM_DFT5U,IDBM_DFT5D,NULL,NULL,IDM_TP_5,NO_HELP,IDI_TIP_5,
00066   IDBM_DFT6U,IDBM_DFT6D,NULL,NULL,IDM_TP_6,NO_HELP,IDI_TIP_6
00067 };
00068 
00069 static int ToolbuttonSize=32,cxToolBtn,cyToolBtn;
00070 
00071 static int FakeCaptionHeight (void){
00072  return (GetSystemMetrics (SM_CYCAPTION) / 3) + 2; // + 5;
00073 }
00074 
00075 static void DrawFakeCaption (HDC dc, HWND Wnd){
00076  HBRUSH hbr;
00077  RECT rClient;
00078  int width, height, brushKind;
00079  GetClientRect (Wnd, &rClient);
00080  rClient.bottom = rClient.top + FakeCaptionHeight();
00081 // brushKind = (GetParent (Wnd) == GetFocus ()) ?
00082 //   COLOR_ACTIVECAPTION : COLOR_INACTIVECAPTION;
00083  brushKind = COLOR_ACTIVECAPTION;
00084  hbr = CreateSolidBrush (GetSysColor (brushKind));
00085  FillRect (dc, &rClient, hbr);
00086  DeleteObject (hbr);
00087 #if 0
00088  { HFONT hf,hfo;
00089    hf=CreateFont(-10, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
00090       ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
00091       DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
00092    "MS Sans Serif"); //      "Arial");
00093    hfo=SelectObject(dc,hf);
00094    SetBkColor(dc,GetSysColor(COLOR_ACTIVECAPTION));
00095    SetTextColor(dc,GetSysColor(COLOR_CAPTIONTEXT));
00096    TextOut(dc,2,1,"Tools",strlen("Tools"));
00097    SelectObject(dc,hfo);
00098    DeleteObject(hf);
00099  }
00100 #endif
00101  MoveToEx(dc, rClient.left, rClient.bottom,NULL);
00102  LineTo(dc, rClient.right, rClient.bottom);
00103 #if 0
00104  rClient.right = (FakeCaptionHeight() * 3) / 2;
00105  MoveToEx(dc, rClient.right, rClient.top,NULL);
00106  LineTo(dc, rClient.right, rClient.bottom);
00107  FillRect (dc, &rClient, GetStockObject (LTGRAY_BRUSH));
00108  width = rClient.right - rClient.left;
00109  rClient.left += (width / 4) + 1;
00110  rClient.right = rClient.left + (width / 2) + 1;
00111  height = rClient.bottom - rClient.top;
00112  rClient.top += height / 2;
00113  rClient.bottom = rClient.top + 3;
00114  FillRect (dc, &rClient, GetStockObject (GRAY_BRUSH));
00115  OffsetRect (&rClient, -1, -1);
00116  FillRect (dc, &rClient, GetStockObject (WHITE_BRUSH));
00117  FrameRect (dc, &rClient, GetStockObject (BLACK_BRUSH));
00118 #endif
00119 }
00120 
00121 static BOOL CaptionHitTest(HWND Wnd, LONG lParam, BOOL CloseBoxOnly){
00122  POINT pt;
00123  RECT rClient;
00124  GetClientRect (Wnd, &rClient);
00125  rClient.bottom = rClient.top + FakeCaptionHeight();
00126  if (CloseBoxOnly) rClient.right = (FakeCaptionHeight() * 3) / 2;
00127  pt.x = LOWORD (lParam);
00128  pt.y = HIWORD (lParam);
00129  ScreenToClient (Wnd, &pt);
00130  return PtInRect (&rClient, pt);
00131 }
00132 
00133 static void ToolboxDestroy(void){
00134  if(hwndDraftTools)DestroyWindow(hwndDraftTools);
00135 }
00136 
00137 static HWND CreateCommandPannel(TOOL_CONTROL aTC[],int n,char *title,
00138                                 int nc,int nr,int x,int y,int gap,
00139                                 HWND parent){
00140  int i,j,cx,cy,captionH;
00141  RECT rc,rc1;
00142  BITMAP bmp;
00143  HWND hwnd,hwndB;
00144  captionH=FakeCaptionHeight();
00145  if(n > 0)for(i=0;i<n;i++){
00146    if((aTC[i].hbmToolBtnUp=LoadBitmap(ghinst_draft,
00147       MAKEINTRESOURCE(aTC[i].idToolBtnUp))) == NULL)return NULL;
00148    if((aTC[i].hbmToolBtnDown=LoadBitmap(ghinst_draft,
00149       MAKEINTRESOURCE(aTC[i].idToolBtnDown))) == NULL)return NULL;
00150  }
00151  cxToolBtn = ToolbuttonSize; /* bmp.bmWidth;  */
00152  cyToolBtn = ToolbuttonSize; /* bmp.bmHeight; */
00153  rc.left=0; rc.top=0;
00154  rc.right=nc*(ToolbuttonSize);
00155  rc.bottom=nr*(ToolbuttonSize);
00156  AdjustWindowRect(&rc,TOOLBOXSTYLE,FALSE);
00157  cx=rc.right-rc.left-1+2;
00158  cy=rc.bottom-rc.top-1+captionH+2;
00159  if((hwnd = CreateWindow(szToolboxClass,title,TOOLBOXSTYLE,
00160     x,y,cx,cy,hwnd_dtools,NULL,ghinst_draft,NULL)) == NULL)return NULL;
00161  hwndTooltip=DoCreateTooltip(hwnd);
00162  x=1; y=ToolbuttonSize*gap+captionH+1;
00163  if(n > 0)for(i=0,j=0;i<n;i++){
00164    hwndB=CreateWindow(szToolBtnClass,NULL,WS_CHILD | WS_VISIBLE,x,y,
00165                       ToolbuttonSize,ToolbuttonSize,
00166                       hwnd,(HMENU)i,ghinst_draft,NULL);
00167    DoAddTooltip(hwnd,hwndB,aTC[i].Tip);
00168    j++;
00169    if(j == nc){
00170      j=0; x=1; y += ToolbuttonSize;
00171    }
00172    else x += ToolbuttonSize;
00173  }
00174  return hwnd;
00175 }
00176 
00177 static void DeleteCommandPannel(TOOL_CONTROL aTC[],int n){
00178  int i;
00179  for(i=0;i<n;i++){
00180    DeleteObject(aTC[i].hbmToolBtnUp);
00181    aTC[i].hbmToolBtnUp = NULL;
00182    DeleteObject(aTC[i].hbmToolBtnDown);
00183    aTC[i].hbmToolBtnDown = NULL;
00184  }
00185 }
00186 
00187 static LRESULT CALLBACK ToolboxWndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam){
00188  RECT r;
00189  switch (msg) {
00190    case WM_CREATE:
00191      return 0;
00192    case WM_NCHITTEST:
00193      if (CaptionHitTest(hwnd,lParam,FALSE))return (HTCAPTION);
00194      return DefWindowProc (hwnd,msg,wParam,lParam);
00195    case WM_NCLBUTTONDOWN:
00196      if(CaptionHitTest (hwnd,lParam,TRUE)){
00197 //       PostMessage(hwnd_dtools,WM_COMMAND,IDM_CLOSETBX,0);
00198      }
00199      return DefWindowProc(hwnd,msg,wParam,lParam);
00200    case WM_KEYDOWN:
00201      SetActiveWindow(GetParent(hwnd));
00202      break;
00203    case WM_NCACTIVATE:
00204      return TRUE;
00205    case WM_ACTIVATE:
00206      GetClientRect(hwnd, &r);
00207      r.bottom = r.top + FakeCaptionHeight();
00208      InvalidateRect (hwnd,&r,FALSE);
00209      return (0);
00210    case WM_PAINT:{
00211        HDC hDC;
00212        COLORREF oldcolour;
00213        PAINTSTRUCT ps;
00214        HFONT holdFont=NULL;
00215        hDC=BeginPaint(hwnd,&ps);
00216        DrawFakeCaption(hDC,hwnd);
00217        GetClientRect(hwnd,&r);
00218        FrameRect(hDC,&r,GetStockObject(BLACK_BRUSH));
00219        EndPaint(hwnd,&ps);
00220      }
00221      break;
00222    case WM_DESTROY:{
00223        if(hwnd == hwndDraftTools){
00224          DeleteCommandPannel(aTools,NTOOLS);
00225          hwndDraftTools = NULL;
00226        }
00227      }
00228      break;
00229    default:
00230      return DefWindowProc(hwnd, msg, wParam, lParam);
00231  }
00232  return 0;
00233 }
00234 
00235 static LRESULT CALLBACK ToolBtnWndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam){
00236  static int captured=0,*lpbuttonid=NULL;
00237  MSG mmsg;
00238  HWND hwnd_parent;
00239  hwnd_parent=GetParent(hwnd);
00240  mmsg.hwnd=hwnd;
00241  mmsg.message=msg;
00242  mmsg.wParam=wParam;
00243  mmsg.lParam=lParam;
00244  switch (msg) {
00245    case WM_MOUSEMOVE:
00246      if(hwndTooltip != NULL)SendMessage(hwndTooltip,TTM_RELAYEVENT,
00247                                         0,(LPARAM)(LPMSG)&mmsg);
00248      if(captured){
00249        RECT rc;
00250        POINT p;
00251        p.x=LOWORD(lParam),p.y=HIWORD(lParam);
00252        ClientToScreen(hwnd,&p);
00253        GetWindowRect(hwnd,&rc);
00254        if(p.x < rc.left || p.x > rc.right || p.y < rc.top || p.y > rc.bottom){
00255          if(lpbuttonid != NULL)PannelSelectTool(hwnd_parent,lpbuttonid,-1);
00256        }
00257        else{
00258          if(lpbuttonid != NULL)PannelSelectTool(hwnd_parent,lpbuttonid,
00259                                (int)GetWindowLong(hwnd,GWL_ID));
00260        }
00261      }
00262      break;
00263    case WM_LBUTTONDOWN:
00264      if(hwndTooltip != NULL)SendMessage(hwndTooltip,TTM_RELAYEVENT,
00265                                         0,(LPARAM)(LPMSG)&mmsg);
00266      if(hwnd_parent == hwndDraftTools )lpbuttonid = &gCurDraftTool;
00267      if(lpbuttonid != NULL)PannelSelectTool(hwnd_parent,lpbuttonid,
00268                            (int)GetWindowLong(hwnd,GWL_ID));
00269      captured=1;
00270      SetCapture(hwnd);
00271      break;
00272    case WM_LBUTTONUP:
00273      if(hwndTooltip != NULL)SendMessage(hwndTooltip,TTM_RELAYEVENT,
00274                                         0,(LPARAM)(LPMSG)&mmsg);
00275      if(lpbuttonid != NULL){
00276        if(hwnd_parent == hwndDraftTools && gCurDraftTool >= 0){
00277          if(aTools[gCurDraftTool].Message != NO_MESSAGE)PostMessage(hwnd_dtools,
00278            WM_COMMAND,aTools[gCurDraftTool].Message,0);
00279          PannelSelectTool(hwnd_parent,&gCurDraftTool,-1);
00280        }
00281      }
00282      captured=0; lpbuttonid=NULL;
00283      ReleaseCapture();
00284      break;
00285    case WM_PAINT:{
00286        HDC hDC;
00287        PAINTSTRUCT ps;
00288        hDC=BeginPaint(hwnd,&ps);
00289        if(hwnd_parent == hwndDraftTools)PannelDrawBitmap(hDC,1,
00290          aTools,(int)GetWindowLong(hwnd,GWL_ID),gCurDraftTool);
00291        EndPaint(hwnd,&ps);
00292      }
00293      break;
00294    default:
00295      return DefWindowProc(hwnd, msg, wParam, lParam);
00296  }
00297  return 0;
00298 }
00299 
00300 static void PannelDrawBitmap(HDC hDC, int tp, TOOL_CONTROL aT[],
00301                              int type, int ctool){
00302  HDC hMemDC;
00303  HBITMAP hbm;
00304  HBITMAP hbmOld;
00305  if(tp == 1){
00306    if(tool < NTOOLS){
00307      hbm = (type == ctool || type == tool) ? aT[type].hbmToolBtnDown : aT[type].hbmToolBtnUp;
00308    }
00309    else{
00310      hbm = (type == ctool || type == 1) ? aT[type].hbmToolBtnDown : aT[type].hbmToolBtnUp;
00311    }
00312  }
00313  else{
00314    hbm = (type == ctool) ? aT[type].hbmToolBtnDown : aT[type].hbmToolBtnUp;
00315  }
00316  if(hbm == NULL)return;
00317  hMemDC = CreateCompatibleDC(hDC);
00318  hbmOld = SelectObject(hMemDC, hbm);
00319  BitBlt(hDC,0,0,cxToolBtn,cyToolBtn,hMemDC,0,0,SRCCOPY);
00320  SelectObject(hMemDC, hbmOld);
00321  DeleteDC(hMemDC);
00322 }
00323 
00324 static void PannelSelectTool(HWND hwnd, int *oldtool, int newtool){
00325  if(hwnd != NULL){
00326    if(*oldtool >= 0)InvalidateRect(GetDlgItem(hwnd,*oldtool),NULL,FALSE);
00327    if( newtool >= 0)InvalidateRect(GetDlgItem(hwnd,newtool),NULL,FALSE);
00328  }
00329  *oldtool=newtool;
00330 }
00331 
00332 BOOL OpenDraftToolbox(HWND hwnd_parent, HINSTANCE hinst_parent){
00333  int x,y,sep=5;
00334  RECT rc,rc1;
00335  WNDCLASS wc;
00336  ghinst_draft=hinst_parent;
00337  hwnd_dtools=hwnd_parent;
00338  wc.lpszClassName = szToolboxClass;
00339  wc.style = 0;
00340  wc.lpfnWndProc = (WNDPROC)ToolboxWndProc;
00341  wc.cbClsExtra = 0;
00342  wc.cbWndExtra = 0;
00343  wc.hInstance = ghinst_draft;
00344  wc.hIcon = NULL;
00345  wc.hCursor = LoadCursor(NULL, IDC_ARROW);
00346  wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
00347  wc.lpszMenuName = NULL;
00348  if(!RegisterClass(&wc))return FALSE;
00349  wc.lpszClassName = szToolBtnClass;
00350  wc.style = 0;
00351  wc.lpfnWndProc = (WNDPROC)ToolBtnWndProc;
00352  wc.cbClsExtra = 0;
00353  wc.cbWndExtra = 0;
00354  wc.hInstance = ghinst_draft;
00355  wc.hIcon = NULL;
00356  wc.hCursor = LoadCursor(NULL, IDC_ARROW);
00357  wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
00358  wc.lpszMenuName = NULL;
00359  if(!RegisterClass(&wc))return FALSE;
00360  GetWindowRect(hwnd_dtools,&rc1);
00361  x=rc1.right-3*ToolbuttonSize;
00362  y=rc1.top+3*ToolbuttonSize;
00363  if((hwndDraftTools=CreateCommandPannel(aTools,NTOOLS," ",
00364                 TOOLCOLUMNS,TOOLROWS,x,y,0,hwnd_parent)) == NULL)return FALSE;
00365  ShowWindow(hwndDraftTools,SW_SHOW);
00366  return TRUE;
00367 }
00368 
00369 void DestroyDraftToolbox(void){
00370  if(hwndDraftTools == NULL)return;
00371  DestroyWindow(hwndDraftTools);
00372  UnregisterClass(szToolboxClass,ghinst_draft);
00373  UnregisterClass(szToolBtnClass,ghinst_draft);
00374 }
00375 
00376 void SelectDraftTool(int nt){
00377  if(hwndDraftTools == NULL)return;
00378  InvalidateRect(GetDlgItem(hwndDraftTools,tool),NULL,FALSE);
00379  tool=nt;
00380  InvalidateRect(GetDlgItem(hwndDraftTools,tool),NULL,FALSE);
00381 }
00382 
00383 static void DoAddTooltip(HWND hwndOwner, HWND tipon, int resid){
00384  TOOLINFO ti;
00385  if(hwndTooltip == NULL || tipon == NULL)return;
00386  memset(&ti,0,sizeof(TOOLINFO));
00387  ti.cbSize = sizeof(TOOLINFO);
00388  ti.uFlags = TTF_IDISHWND;
00389  ti.hwnd = hwndOwner;
00390  ti.hinst = ghinst_draft;
00391  ti.uId = (UINT)tipon;
00392  ti.lpszText = (LPSTR)resid;
00393  SendMessage(hwndTooltip,TTM_ADDTOOL,0,(LPARAM) (LPTOOLINFO) &ti);
00394  return;
00395 }
00396 
00397 static HWND DoCreateTooltip(HWND hwndOwner){
00398  HWND hwndTT;
00399  hwndTT = CreateWindow(TOOLTIPS_CLASS, (LPSTR) NULL, TTS_ALWAYSTIP,
00400      CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
00401      hwndOwner, (HMENU) NULL, ghinst_draft, NULL);
00402  return hwndTT;
00403 }

Generated on Sun Apr 27 14:20:10 2014 for OpenFX by  doxygen 1.5.6