Files
Work/mdiwin/PALTDLG.CPP
2024-08-07 09:16:27 -04:00

168 lines
4.1 KiB
C++
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include <stdio.h>
#include <mdiwin/windowsx.hpp>
#include <mdiwin/main.hpp>
#include <mdiwin/string.hpp>
#include <mdiwin/paltdlg.hpp>
#include <mdiwin/mdiwin.h>
PaletteDialog::PaletteDialog(HWND hParent,HPALETTE hPalette)
: mhParent(hParent), mhPalette(hPalette)
{
PALETTEENTRY lpPaletteEntry[256];
mNumColors=::GetPaletteEntries(mhPalette,0,256,(PALETTEENTRY FAR *)&lpPaletteEntry);
}
PaletteDialog::~PaletteDialog()
{
}
void PaletteDialog::showPalette(void)
{
HINSTANCE hInstance;
#if defined (__FLAT__)
hInstance=(HINSTANCE)::GetWindowLong(mhParent,GWL_HINSTANCE);
#else
hInstance=(HINSTANCE)::GetWindowWord(mhParent,GWW_HINSTANCE);
#endif
::DialogBoxParam(hInstance,(LPSTR)"Palette",mhParent,(DLGPROC)DWindow::DialogProcedure,(LONG)((DWindow*)this));
}
int PaletteDialog::DlgProc(UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_INITDIALOG :
Main::smhBitmap.associate(IDOK,
String(STRING_BITMAPOKFOCUSUP,Main::processInstance()),
String(STRING_BITMAPOKNOFUP,Main::processInstance()),
String(STRING_BITMAPOKFOCUSDN,Main::processInstance()),
OwnerDraw::NOFOCUS);
mhGroupWindow=::GetDlgItem(GetHandle(),PALETTE_COLORS);
setWindowSize();
return TRUE;
case WM_DRAWITEM :
switch(((LPDRAWITEMSTRUCT)lParam)->CtlID)
{
case IDOK :
Main::smhBitmap.handleOwnerButton(IDOK,lParam);
break;
case PALETTE_COLORS :
if(ODA_DRAWENTIRE==((LPDRAWITEMSTRUCT)lParam)->itemAction)
drawPaletteColors();
break;
}
return TRUE;
case WM_COMMAND :
switch(GET_WM_COMMAND_ID(wParam,lParam))
{
case IDOK :
Main::smhBitmap.freeButton(IDOK);
::EndDialog(GetHandle(),TRUE);
return TRUE;
}
}
return FALSE;
}
void PaletteDialog::drawPaletteColors(void)const
{
HDC hDC;
HBRUSH hBrush;
HBRUSH hOldBrush;
HPALETTE hOldPalette;
HPEN hOldPen;
RECT winRect;
short xStart=1;
short yStart=1;
::GetClientRect(mhGroupWindow,(RECT FAR *)&winRect);
hDC=::GetDC(mhGroupWindow);
hOldPalette=::SelectPalette(hDC,mhPalette,FALSE);
::RealizePalette(hDC);
hOldPen=(HPEN)::SelectObject(hDC,::GetStockObject(BLACK_PEN));
for(int i=0;i<mNumColors;i++)
{
hBrush=::CreateSolidBrush(PALETTEINDEX(i));
hOldBrush=(HBRUSH)::SelectObject(hDC,hBrush);
::Rectangle(hDC,xStart,yStart,xStart+DELTAX,yStart+DELTAY);
::SelectObject(hDC,hOldBrush);
::DeleteObject(hBrush);
xStart=(xStart+DELTAX);
if(xStart+DELTAX>=winRect.right)
{
if(yStart+DELTAY>winRect.bottom)break;
xStart=1;
yStart=(yStart+DELTAY);
}
}
::SelectObject(hDC,hOldPen);
::SelectPalette(hDC,hOldPalette,FALSE);
::ReleaseDC(mhGroupWindow,hDC);
return;
}
void PaletteDialog::conformWindow(int heightRegion)const
{
RECT winRect;
RECT grpRect;
UINT yRelative;
WORD xLen;
WORD yLen;
::GetClientRect(mhGroupWindow,(RECT FAR *)&grpRect);
heightRegion=grpRect.bottom-heightRegion;
::GetWindowRect(GetHandle(),(RECT FAR *)&winRect);
::GetWindowRect(mhGroupWindow,(RECT FAR *)&grpRect);
yRelative=winRect.bottom-grpRect.bottom;
grpRect.bottom-=heightRegion;
winRect.bottom=grpRect.bottom+yRelative;
makeClientRect(grpRect);
xLen=grpRect.right-grpRect.left;
yLen=grpRect.bottom-grpRect.top;
::MoveWindow(mhGroupWindow,grpRect.left,grpRect.top,xLen,yLen,TRUE);
xLen=winRect.right-winRect.left;
yLen=winRect.bottom-winRect.top;
::MoveWindow(GetHandle(),winRect.left,winRect.top,xLen,yLen,TRUE);
return;
}
void PaletteDialog::makeClientRect(RECT &screenRect)const
{
POINT pt;
pt.x=screenRect.left;
pt.y=screenRect.top;
::ScreenToClient(GetHandle(),(POINT FAR *)&pt);
screenRect.left=pt.x;
screenRect.top=pt.y;
pt.x=screenRect.right;
pt.y=screenRect.bottom;
::ScreenToClient(GetHandle(),(POINT FAR *)&pt);
screenRect.right=pt.x;
screenRect.bottom=pt.y;
return;
}
void PaletteDialog::setWindowSize(void)const
{
RECT winRect;
short xStart=1;
short yStart=1;
::GetClientRect(mhGroupWindow,(RECT FAR *)&winRect);
for(int i=0;i<mNumColors;i++)
{
xStart=(xStart+DELTAX);
if(xStart+DELTAX>=winRect.right)
{
if(yStart+DELTAY>winRect.bottom)break;
xStart=1;
yStart=(yStart+DELTAY);
}
}
conformWindow(yStart+DELTAY);
return;
}