|
From: <kr_...@us...> - 2003-07-08 20:31:32
|
Update of /cvsroot/htoolkit/port/src/cbits/Win32
In directory sc8-pr-cvs1:/tmp/cvs-serv14568/src/cbits/Win32
Added Files:
ControlBar.c ControlBar.h ToolBar.c
Log Message:
Added implementation for ToolBar. The Windows version is still in very basic
state.
--- NEW FILE: ControlBar.c ---
#include "Types.h"
#include "Internals.h"
#include "ControlBar.h"
#include "Handlers_stub.h"
int GetControlBarSize(HWND hControlBar)
{
HWND hCtrl;
LONG lStyle;
int nSize;
RECT rect;
lStyle = GetWindowLong(hControlBar, GWL_STYLE);
nSize = 0;
hCtrl = GetTopWindow(hControlBar);
while (hCtrl)
{
GetClientRect(hCtrl,&rect);
nSize = max(nSize, (lStyle & CCS_VERT) ? rect.right : rect.bottom);
hCtrl = GetNextWindow(hCtrl,GW_HWNDNEXT);
}
return nSize;
}
void RelayoutFrameBars()
{
RECT rect;
FrameData *pData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA);
int nWidth, nHeight, nLeft, nTop, nRight, nBottom;
GetClientRect(ghWndFrame, &rect);
nWidth = rect.right-rect.left;
nHeight = rect.bottom-rect.top;
nLeft = GetControlBarSize(pData->hLeftBar);
nTop = GetControlBarSize(pData->hTopBar);
nRight = GetControlBarSize(pData->hRightBar);
nBottom = GetControlBarSize(pData->hBottomBar);
SetWindowPos(pData->hLeftBar, NULL,0,nTop,nLeft,nHeight-(nBottom+nTop),SWP_NOZORDER);
SetWindowPos(pData->hTopBar, NULL,0,0,nWidth,nTop,SWP_NOZORDER);
SetWindowPos(pData->hRightBar, NULL,nWidth-nRight,nTop,nRight,nHeight-(nBottom+nTop),SWP_NOZORDER);
SetWindowPos(pData->hBottomBar,NULL,0,nHeight-nBottom,nWidth,nBottom,SWP_NOZORDER);
SetWindowPos(pData->hClientWnd,NULL,nLeft,nTop,nWidth-(nRight+nLeft),nHeight-(nBottom+nTop),SWP_NOZORDER);
}
LRESULT CALLBACK HControlBarFunction(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HWND hToolBar;
TBBUTTONINFO tbbi;
tbbi.cbSize = sizeof(tbbi);
tbbi.dwMask = TBIF_LPARAM;
tbbi.lParam = NULL;
switch (uMsg)
{
case WM_COMMAND:
{
hToolBar = (HWND) lParam;
SendMessage(hToolBar, TB_GETBUTTONINFO, LOWORD(wParam), (LPARAM) &tbbi);
handleToolCommand((WindowHandle) tbbi.lParam);
}
break;
case WM_NOTIFY:
{
LPNMTTDISPINFO lpnmtdi = (LPNMTTDISPINFO) lParam;
if (lpnmtdi->hdr.code == TTN_NEEDTEXT)
{
hToolBar = lpnmtdi->lParam;
printf("2> hToolBar=%p\n", hToolBar);
printf("2> lpnmtdi->hdr.idFrom=%p\n", lpnmtdi->hdr.idFrom);
SendMessage(hToolBar, TB_GETBUTTONINFO, lpnmtdi->hdr.idFrom, (LPARAM) &tbbi);
printf("2> tbbi.lParam=%p\n", tbbi.lParam);
printf("2> lpnmtdi->lParam=%p\n", lpnmtdi->lParam);
//lpnmtdi->lpszText = ((ToolButton) tbbi.lParam)->lpszToolTip;
}
}
break;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
--- NEW FILE: ControlBar.h ---
#ifndef CONTROLBAR_H
#define CONTROLBAR_H
int GetControlBarSize(HWND hControlBar);
void RelayoutFrameBars();
#endif
--- NEW FILE: ToolBar.c ---
#include "ToolBar.h"
#include "ControlBar.h"
#include "Internals.h"
typedef struct _ToolHandle
{
int nCommand;
HWND hToolBar;
BitmapHandle bitmap;
};
static int nNextToolButtonID = 0;
WindowHandle osCreateToolBar(int nPlace)
{
HWND hControlBar, hWnd;
FrameData *pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA);
switch (nPlace)
{
case 0: hControlBar = pFrameData->hLeftBar; break;
case 1: hControlBar = pFrameData->hTopBar; break;
case 2: hControlBar = pFrameData->hRightBar; break;
case 3: hControlBar = pFrameData->hBottomBar; break;
}
hWnd = CreateWindow (TOOLBARCLASSNAME,
NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER | WS_CLIPSIBLINGS | CCS_TOP | TBSTYLE_TOOLTIPS | TBSTYLE_AUTOSIZE | TBSTYLE_FLAT,
0,0,0,0,
hControlBar,
(HMENU) NULL,
(HANDLE) ghModule,
0
);
SendMessage (hWnd, TB_AUTOSIZE, (WPARAM)0, (LPARAM)0);
SendMessage (hWnd, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), (LPARAM) 0);
return hWnd;
}
ToolHandle osInsertToolButton(WindowHandle toolBar, int pos)
{
TBBUTTON tbb;
ToolHandle btn;
btn = malloc(sizeof(struct _ToolHandle));
if (!btn) return NULL;
btn->nCommand = ++nNextToolButtonID;
btn->hToolBar = toolBar;
btn->bitmap = NULL;
tbb.iBitmap = I_IMAGENONE;
tbb.idCommand = btn->nCommand;
tbb.fsState = (BYTE)TBSTATE_ENABLED;
tbb.fsStyle = (BYTE)TBSTYLE_BUTTON;
tbb.dwData = (DWORD)btn;
tbb.iString = 0;
if (pos > 0)
SendMessage(toolBar,TB_INSERTBUTTON,pos,(LPARAM)&tbb);
else
SendMessage(toolBar, TB_ADDBUTTONS, 1, (LPARAM)&tbb);
RelayoutFrameBars();
return btn;
}
ToolHandle osInsertToolCheckButton(WindowHandle toolBar, int pos)
{
return NULL;
}
ToolHandle osInsertToolLine(WindowHandle toolBar, int pos)
{
TBBUTTON tbb;
ToolHandle btn;
btn = malloc(sizeof(struct _ToolHandle));
if (!btn) return NULL;
btn->nCommand = ++nNextToolButtonID;
btn->hToolBar = toolBar;
btn->bitmap = NULL;
tbb.iBitmap = 1;
tbb.idCommand = btn->nCommand;
tbb.fsState = (BYTE)TBSTATE_ENABLED;
tbb.fsStyle = (BYTE)TBSTYLE_SEP;
tbb.dwData = (DWORD)btn;
tbb.iString = 0;
if (pos > 0)
SendMessage(toolBar,TB_INSERTBUTTON,pos,(LPARAM)&tbb);
else
SendMessage(toolBar, TB_ADDBUTTONS, 1, (LPARAM)&tbb);
RelayoutFrameBars();
return btn;
}
void osSetToolButtonBitmap(ToolHandle toolButton, BitmapHandle bitmap)
{
TBBUTTONINFO tbbi;
tbbi.cbSize = sizeof(tbbi);
tbbi.dwMask = TBIF_IMAGE;
tbbi.iImage = I_IMAGENONE;
SendMessage(toolButton->hToolBar, TB_GETBUTTONINFO, toolButton->nCommand, (LPARAM) &tbbi);
if (tbbi.iImage == I_IMAGENONE)
{
TBADDBITMAP tbab;
tbab.hInst = NULL;
tbab.nID = (UINT) bitmap->hBitmap;
tbbi.iImage = SendMessage(toolButton->hToolBar, TB_ADDBITMAP, 1, (LPARAM) &tbab);
SendMessage(toolButton->hToolBar, TB_SETBUTTONINFO, toolButton->nCommand, (LPARAM) &tbbi);
}
else
{
TBREPLACEBITMAP tbrb;
tbrb.hInstOld = NULL;
tbrb.nIDOld = (UINT) toolButton->bitmap->hBitmap;
tbrb.hInstNew = NULL;
tbrb.nIDNew = (UINT) bitmap->hBitmap;
tbrb.nButtons = 1;
SendMessage(toolButton->hToolBar, TB_REPLACEBITMAP, 0, (LPARAM) &tbrb);
}
toolButton->bitmap = bitmap;
InvalidateRect(toolButton->hToolBar,NULL,TRUE);
}
void osSetToolButtonEnabled(ToolHandle toolButton, BOOL bEnabled)
{
SendMessage(toolButton->hToolBar, TB_ENABLEBUTTON, toolButton->nCommand, (LPARAM) bEnabled);
}
BOOL osGetToolButtonEnabled(ToolHandle toolButton)
{
TBBUTTONINFO tbbi;
tbbi.cbSize = sizeof(tbbi);
tbbi.dwMask = TBIF_STATE;
tbbi.fsState= 0;
SendMessage(toolButton->hToolBar, TB_GETBUTTONINFO, toolButton->nCommand, (LPARAM) &tbbi);
return (tbbi.fsState & TBSTATE_ENABLED);
}
void osSetToolButtonTip(ToolHandle toolButton, char *text)
{
TOOLINFO ti; /* The tool information that is sent to the tooltip control. */
if (strlen(text) > 256) // Truncate the tip text to 255 chars because the osGetToolButtonTip function
text[256] = 0; //uses 256 bytes long buffer
/* Fill the tooltip info with the appropriate information. */
ti.cbSize = sizeof(TOOLINFO);
ti.uFlags = TTF_SUBCLASS;
ti.hwnd = toolButton->hToolBar;
ti.uId = toolButton->nCommand;
ti.rect.left = 0;
ti.rect.top = 0;
ti.rect.right = 0;
ti.rect.bottom= 0;
ti.hinst = ghModule;
ti.lpszText = text;
SendMessage ((HWND) SendMessage(toolButton->hToolBar, TB_GETTOOLTIPS, 0, 0), TTM_SETTOOLINFO, 0, (LPARAM) (LPTOOLINFO)&ti);
}
char *osGetToolButtonTip(ToolHandle toolButton)
{
TOOLINFO ti; /* The tool information that is sent to the tooltip control. */
/* Fill the tooltip info with the appropriate information. */
ti.cbSize = sizeof(TOOLINFO);
ti.uFlags = TTF_SUBCLASS;
ti.hwnd = toolButton->hToolBar;
ti.uId = toolButton->nCommand;
ti.rect.left = 0;
ti.rect.top = 0;
ti.rect.right = 0;
ti.rect.bottom= 0;
ti.hinst = ghModule;
ti.lpszText = malloc(256);
SendMessage ((HWND) SendMessage(toolButton->hToolBar, TB_GETTOOLTIPS, 0, 0), TTM_GETTOOLINFO, 0, (LPARAM) (LPTOOLINFO)&ti);
return ti.lpszText;
}
void osSetToolButtonChecked(ToolHandle toolButton, BOOL bState)
{
};
BOOL osGetToolButtonChecked(ToolHandle toolButton)
{
return FALSE;
}
int osGetToolItemPos(ToolHandle toolButton)
{
return SendMessage(toolButton->hToolBar, TB_COMMANDTOINDEX, toolButton->nCommand, 0);
}
|