"Fossies" - the Fresh Open Source Software Archive

Member "tvnserver-2.0.4/gui/Control.cpp" (3 Aug 2011, 4303 Bytes) of archive /windows/misc/tvnserver-2.0.4-src.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Control.cpp" see the Fossies "Dox" file reference documentation.

    1 // Copyright (C) 2008, 2009, 2010 GlavSoft LLC.
    2 // All rights reserved.
    3 //
    4 //-------------------------------------------------------------------------
    5 // This file is part of the TightVNC software.  Please visit our Web site:
    6 //
    7 //                       http://www.tightvnc.com/
    8 //
    9 // This program is free software; you can redistribute it and/or modify
   10 // it under the terms of the GNU General Public License as published by
   11 // the Free Software Foundation; either version 2 of the License, or
   12 // (at your option) any later version.
   13 //
   14 // This program is distributed in the hope that it will be useful,
   15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
   16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17 // GNU General Public License for more details.
   18 //
   19 // You should have received a copy of the GNU General Public License along
   20 // with this program; if not, write to the Free Software Foundation, Inc.,
   21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   22 //-------------------------------------------------------------------------
   23 //
   24 
   25 #include "Control.h"
   26 
   27 Control::Control()
   28 : m_hwnd(NULL)
   29 {
   30 }
   31 
   32 Control::Control(HWND hwnd)
   33 : m_hwnd(hwnd)
   34 {
   35 }
   36 
   37 Control::~Control()
   38 {
   39 }
   40 
   41 void Control::setWindow(HWND hwnd)
   42 {
   43   m_hwnd = hwnd;
   44   m_defWindowProc = (WNDPROC)GetWindowLongPtr(m_hwnd, GWLP_WNDPROC);
   45 }
   46 
   47 void Control::setEnabled(bool enabled)
   48 {
   49   if (enabled) {
   50     SendMessage(m_hwnd, WM_ENABLE, TRUE, NULL);
   51     removeStyle(WS_DISABLED);
   52   } else {
   53     if (isStyleEnabled(WS_DISABLED)) {
   54       return ;
   55     } 
   56     SendMessage(m_hwnd, WM_ENABLE, FALSE, NULL);
   57     addStyle(WS_DISABLED);
   58   }
   59   invalidate();
   60 }
   61 
   62 void Control::setText(const TCHAR *text)
   63 {
   64   SetWindowText(m_hwnd, text);
   65 }
   66 
   67 void Control::setSignedInt(int value)
   68 {
   69   StringStorage text;
   70   text.format(_T("%d"), value);
   71   setText(text.getString());
   72 }
   73 
   74 void Control::setUnsignedInt(unsigned int value)
   75 {
   76   StringStorage text;
   77   text.format(_T("%u"), value);
   78   setText(text.getString());
   79 }
   80 
   81 void Control::setTextVerticalAlignment(VerticalAlignment align)
   82 {
   83 }
   84 
   85 void Control::setFocus()
   86 {
   87   ::SetFocus(m_hwnd);
   88 }
   89 
   90 bool Control::hasFocus()
   91 {
   92   return (::GetFocus() == m_hwnd) || (GetForegroundWindow() == m_hwnd);
   93 }
   94 
   95 bool Control::setForeground()
   96 {
   97   return SetForegroundWindow(getWindow()) != 0;
   98 }
   99 
  100 void Control::setVisible(bool visible)
  101 {
  102   ShowWindow(m_hwnd, visible ? SW_SHOW : SW_HIDE);
  103 }
  104 
  105 bool Control::isEnabled()
  106 {
  107   return (!isStyleEnabled(WS_DISABLED));
  108 }
  109 
  110 void Control::invalidate()
  111 {
  112   InvalidateRect(m_hwnd, NULL, TRUE);
  113 }
  114 
  115 void Control::getText(StringStorage *storage)
  116 {
  117   int length = SendMessage(m_hwnd, WM_GETTEXTLENGTH, 0, 0);
  118   TCHAR *buf = new TCHAR[length + 1];
  119   GetWindowText(m_hwnd, buf, length + 1);
  120   storage->setString(buf);
  121   delete []buf;
  122 }
  123 
  124 VerticalAlignment Control::getTextVerticalAlignment()
  125 {
  126   return Left;
  127 }
  128 
  129 HWND Control::getWindow()
  130 {
  131   return m_hwnd;
  132 }
  133 
  134 void Control::setStyle(DWORD style)
  135 {
  136   ::SetWindowLong(m_hwnd, GWL_STYLE, style);
  137 }
  138 
  139 DWORD Control::getStyle()
  140 {
  141   return ::GetWindowLong(m_hwnd, GWL_STYLE);
  142 }
  143 
  144 void Control::addStyle(DWORD styleFlag)
  145 {
  146   DWORD flags = getStyle();
  147   flags |= styleFlag;
  148   setStyle(flags);
  149 }
  150 
  151 void Control::removeStyle(DWORD styleFlag)
  152 {
  153   DWORD flags = getStyle();
  154   flags &= ~styleFlag;
  155   setStyle(flags);
  156 }
  157 
  158 bool Control::isStyleEnabled(DWORD styleFlag)
  159 {
  160   DWORD flags = getStyle();
  161   return (flags & styleFlag) == styleFlag;
  162 }
  163 
  164 void Control::setExStyle(DWORD style)
  165 {
  166   SetWindowLong(m_hwnd, GWL_EXSTYLE, style);
  167 }
  168 
  169 DWORD Control::getExStyle()
  170 {
  171   return (DWORD)GetWindowLong(m_hwnd, GWL_EXSTYLE);
  172 }
  173 
  174 void Control::addExStyle(DWORD styleFlag)
  175 {
  176   DWORD flags = getExStyle();
  177   flags |= styleFlag;
  178   setExStyle(flags);
  179 }
  180 
  181 void Control::removeExStyle(DWORD styleFlag)
  182 {
  183   DWORD flags = getExStyle();
  184   flags &= ~styleFlag;
  185   setExStyle(flags);
  186 }
  187 
  188 bool Control::isExStyleEnabled(DWORD styleFlag)
  189 {
  190   DWORD flags = getExStyle();
  191   return (flags & styleFlag) == styleFlag;
  192 }
  193 
  194 void Control::replaceWindowProc(WNDPROC wndProc)
  195 {
  196   SetWindowLong(m_hwnd, GWL_USERDATA, (LONG)this);
  197   SetWindowLongPtr(m_hwnd, GWLP_WNDPROC, (LONG)wndProc);
  198 }