Files
Work/common/Status.hpp
2024-08-07 09:09:36 -04:00

154 lines
4.3 KiB
C++

#ifndef _COMMON_STATUSWINDOW_HPP_
#define _COMMON_STATUSWINDOW_HPP_
#ifndef _COMMON_CONTROL_HPP_
#include <common/control.hpp>
#endif
#ifndef _COMMON_COMMCTRL_HPP_
#include <common/commctrl.hpp>
#endif
#ifndef _COMMON_GLOBALDATA_HPP_
#include <common/gdata.hpp>
#endif
class StatusControl : public Control
{
public:
enum DrawType{DrawNormal=0,DrawNoBorders=SBT_NOBORDERS,DrawOwnerDraw=SBT_OWNERDRAW,DrawPopout=SBT_POPOUT,DrawRTLReading=SBT_RTLREADING};
enum {FirstPart=0,SimplePart=255};
StatusControl(void);
virtual ~StatusControl();
HWND createControl(const String &windowName,HWND hParentWnd,UINT controlID);
HWND createControl(const String &windowName,DWORD dwStyle,const Rect &initRect,HWND hParentWnd,int controlID);
BOOL getBorders(int &horzBorder,int &vertBorder,int &rectBorder)const;
UINT getParts(GlobalData<int> &rightCoords)const;
BOOL setParts(GlobalData<int> &partsWidths)const;
BOOL getRect(Rect &partRect,UINT partIndex=0)const;
BOOL getText(String &controlText,UINT partIndex=0)const;
UINT getTextLength(UINT partIndex)const;
void setMinHeight(WORD minHeight)const;
BOOL setText(const String &strText,UINT partIndex=FirstPart,DrawType drawType=DrawNormal)const;
BOOL simple(BOOL simple)const;
UINT numParts(void)const;
private:
enum{MaxParts=255};
StatusControl(const StatusControl &statusControl);
StatusControl &operator=(const StatusControl &statusControl);
};
inline
StatusControl::StatusControl(void)
{
InitCommonControls();
}
inline
StatusControl::~StatusControl()
{
}
inline
StatusControl::StatusControl(const StatusControl &statusControl)
{ // private implementation
*this=statusControl;
}
inline
StatusControl &StatusControl::operator=(const StatusControl &statusControl)
{ // private implementation
return *this;
}
inline
HWND StatusControl::createControl(const String &windowName,DWORD dwStyle,const Rect &initRect,HWND hParentWnd,int controlID)
{
if(isValid())return FALSE;
return Control::createControl(STATUSCLASSNAME,windowName,dwStyle,initRect,hParentWnd,controlID);
}
inline
HWND StatusControl::createControl(const String &windowName,HWND hParentWnd,UINT controlID)
{
if(isValid())return FALSE;
return Control::createControl(STATUSCLASSNAME,windowName,WS_VISIBLE|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,Rect(CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT),hParentWnd,controlID);
}
inline
UINT StatusControl::numParts(void)const
{
if(!isValid())return FALSE;
return sendMessage(SB_GETPARTS,0,0);
}
inline
BOOL StatusControl::getBorders(int &horzBorder,int &vertBorder,int &rectBorder)const
{
int statBorders[3];
if(!isValid()||!sendMessage(SB_GETBORDERS,0,(LPARAM)(LPINT)statBorders))return FALSE;
horzBorder=statBorders[0];
vertBorder=statBorders[1];
rectBorder=statBorders[2];
return TRUE;
}
inline
UINT StatusControl::getParts(GlobalData<int> &rightCoords)const
{
if(!isValid())return FALSE;
rightCoords.size(numParts());
if(!rightCoords.size())return FALSE;
return sendMessage(SB_GETPARTS,rightCoords.size(),(LPARAM)(int*)&rightCoords[0]);
}
inline
BOOL StatusControl::setParts(GlobalData<int> &partsWidths)const
{
if(!isValid()||!partsWidths.size()||partsWidths.size()>MaxParts)return FALSE;
return sendMessage(SB_SETPARTS,(WPARAM)partsWidths.size(),(LPARAM)(int*)&partsWidths[0]);
}
inline
BOOL StatusControl::getRect(Rect &partRect,UINT partIndex)const
{
if(!isValid())return FALSE;
return sendMessage(SB_GETRECT,(WPARAM)partIndex,(LPARAM)(RECT*)partRect);
}
inline
BOOL StatusControl::getText(String &controlText,UINT partIndex)const
{
if(!isValid())return FALSE;
controlText.reserve(getTextLength(partIndex)+1);
sendMessage(SB_GETTEXT,(WPARAM)partIndex,(LPARAM)(char*)controlText);
return controlText.isNull();
}
inline
UINT StatusControl::getTextLength(UINT partIndex)const
{
if(!isValid())return FALSE;
return LOWORD(sendMessage(SB_GETTEXTLENGTH,(WPARAM)partIndex,0L));
}
inline
void StatusControl::setMinHeight(WORD minHeight)const
{
if(!isValid())return;
sendMessage(SB_SETMINHEIGHT,(WPARAM)minHeight,0L);
}
inline
BOOL StatusControl::setText(const String &strText,UINT partIndex,DrawType drawType)const
{
if(!isValid()||strText.isNull())return FALSE;
return sendMessage(SB_SETTEXT,(WPARAM)(partIndex|(UINT)drawType),(LPARAM)(char*)(String&)strText);
}
inline
BOOL StatusControl::simple(BOOL simple)const
{
if(!isValid())return FALSE;
return sendMessage(SB_SIMPLE,(WPARAM)simple,0L);
}
#endif