00001 #ifdef WIN32
00002 #pragma warning(disable : 4786 )
00003 #endif
00004
00005 #include "CSCheckBox.h"
00006 #include "CSBorder.h"
00007 #include "CSFont.h"
00008 #include "CSLAF.h"
00009
00010 const char *CSCheckBox::CLASS = "CSCheckBox";
00011
00012 CSCheckBox::CSCheckBox(void) : CSGrafikElement(0, 0)
00013 {
00014 static char *functionName="CSCheckBox";
00015 LOG_ENTER
00016 mCheckState = false;
00017 mState = BUTTON_DEFAULT;
00018 setLayoutManager(new CSLayoutManagerXY());
00019
00020 MESSAGE_CHECKBOX_CHANGED.setSubtype(CHECKBOX_CHANGED_MESSAGE);
00021 layoutSetup();
00022 LOG_EXIT
00023 }
00024
00025 void CSCheckBox::paint(SDL_Surface *destination, SDL_Rect *parentViewport)
00026 {
00027 static char *functionName="paint";
00028 SDL_Rect elementArea = getElementArea();
00029 elementArea.x += parentViewport->x;
00030 elementArea.y += parentViewport->y;
00031
00032 if (mCheckState)
00033 {
00034 int w = getWidth() - getBorder()->getTotalWidth() -1;
00035 int x = getBorder()->getSizeWest() + mInset.getSizeWest();
00036 int y = getBorder()->getSizeNorth() + mInset.getSizeNorth();
00037 line(destination, &elementArea,x,y+2*w/3,x+w/3,y+w,0x000000);
00038 line(destination, &elementArea,x+w/3,y+w,x+w,y,0x000000);
00039 x++;
00040 line(destination, &elementArea,x,y+2*w/3,x+w/3,y+w,0x000000);
00041 line(destination, &elementArea,x+w/3,y+w,x+w,y,0x000000);
00042 }
00043 }
00044
00045 void CSCheckBox::reactOnMessage(CSMessage *message)
00046 {
00047 reactOnMessageCheckBox(message);
00048 }
00049
00050 void CSCheckBox::reactOnMessageCheckBox(CSMessage *message)
00051 {
00052 static char *functionName="reactOnMessage";
00053 if (message->mIsHandled)
00054 {
00055 reactOnMessageGrafikElement(message);
00056 return;
00057 }
00058 if (message->getType() == GUI_MESSAGE)
00059 {
00060 GuiMessage *gm = (GuiMessage *) message;
00061 if (gm->receiver != this)
00062 {
00063 if (message->getSubtype() == MOUSE_BUTTON_RELEASED_MESSAGE)
00064 {
00065 mState = mState & (~BUTTON_PRESSED);
00066 gm->mIsHandled = true;
00067 }
00068 }
00069 else
00070 {
00071 switch (message->getSubtype())
00072 {
00073 case MOUSE_BUTTON_RELEASED_MESSAGE:
00074 {
00075 mState = mState & (~BUTTON_PRESSED);
00076 MESSAGE_CHECKBOX_CHANGED.actionId = mActionId;
00077 MESSAGE_CHECKBOX_CHANGED.newCheckBoxState = mCheckState;
00078 MESSAGE_CHECKBOX_CHANGED.mIsHandled = false;
00079 sendMessage(MESSAGE_CHECKBOX_CHANGED);
00080 gm->mIsHandled = true;
00081 break;
00082 }
00083
00084 case MOUSE_BUTTON_PRESSED_MESSAGE:
00085 {
00086 if (mState & BUTTON_ENABLED)
00087 {
00088 mState = mState | BUTTON_PRESSED;
00089 mCheckState = !mCheckState;
00090
00091
00092 }
00093 gm->mIsHandled = true;
00094 break;
00095 }
00096 }
00097 }
00098 }
00099 reactOnMessageGrafikElement(message);
00100 }
00101
00102 void CSCheckBox::layoutSetupCheckBox()
00103 {
00104 static char *functionName="layoutSetupCheckBox";
00105 LOG_ENTER
00106 CSLAF *laf = CSLAF::getCurrentLAF();
00107
00108 mMinHeight = laf->getCheckBoxSize() - mInset.getTotalHeight() - getBorder()->getTotalHeight();
00109 mMinWidth = mMinHeight;
00110
00111 mHeight = mMinHeight + mInset.getTotalHeight() + getBorder()->getTotalHeight();
00112 mWidth = mHeight;
00113
00114 LOG_EXIT
00115 }