Пример #1
0
//
/// Sets the text of the gadget. If the given text is blank, then we attempt to
/// load the text from the menu or tooltip.
//
void
TButtonTextGadget::SetText(const tstring& text, bool repaint)
{
  if (text == Text) return;
  Text = text;

  if (Text.length() == 0 && (Style & sText) && GetGadgetWindow())
  {
    TWindow* parent = GetGadgetWindow()->GetParentO();
    TDecoratedFrame* frame= parent ? dynamic_cast<TDecoratedFrame*>(parent) : 0;
    while (parent && !frame){
      parent = parent->GetParentO();
      if (parent)
        frame = dynamic_cast<TDecoratedFrame*>(parent);
    }
    CHECK(frame);
    Text = frame->GetHintText(GetResId().GetInt(), htTooltip);
  }

  if (GetGadgetWindow() && repaint)
  {
    GetGadgetWindow()->GadgetChangedSize(*this);
    Invalidate();
  }
}
Пример #2
0
//
/// Sets the font to be used by the gadget. If repaint is true, calls
/// TGadgetWindow::GadgetChangedSize to recalculate the size of the gadget.
//
void
TButtonTextGadget::SetFont(const TFont& font, bool repaint)
{
  delete Font;
  Font = new TFont(font);
  if (GetGadgetWindow() && repaint)
    GetGadgetWindow()->GadgetChangedSize(*this);
}
Пример #3
0
//
/// Set Font to be used by the Gadget. If repaint is true calls
/// Window->GadgetChangedSize(*this) to recalculate size of gadget.
//
void
TButtonTextGadget::SetFont(TFont* font, bool repaint)
{
  delete Font;
  Font = font;
  if (GetGadgetWindow() && repaint)
    GetGadgetWindow()->GadgetChangedSize(*this);
}
Пример #4
0
//
/// If the style stored in Style is not the same as the new style, SetStyle sets
/// Style to the new style, and then if repaint is true calls
/// Window->GadgetChangedSize(*this) to recalculate size of gadget.
//
void
TButtonTextGadget::SetStyle(TStyle style, bool repaint)
{
  if(Style != style){
    Style = style;
    if (GetGadgetWindow() && repaint)
      GetGadgetWindow()->GadgetChangedSize(*this);
  }
}
Пример #5
0
//
/// If the style stored in LayoutStyle is not the same as the new style,
/// SetLayoutStyle sets LayoutStyle to the new style, and then if repaint is true
/// calls Window->GadgetChangedSize(*this) to recalculate size of gadget.
//
void
TButtonTextGadget::SetLayoutStyle(const TLayoutStyle style, bool repaint)
{
  if(LayoutStyle != style){
    LayoutStyle = style;
    if (GetGadgetWindow() && repaint)
      GetGadgetWindow()->GadgetChangedSize(*this);
  }
}
Пример #6
0
void TDynamicTextGadget::CommandEnable()
{ 
  PRECONDITION(GetGadgetWindow());

  // Must send, not post here, since a ptr to a temp is passed
  //
  // This might be called during idle processing before the
  // HWND has created.  Therefore, confirm handle exists.
  //
  if (GetGadgetWindow()->GetHandle()){
    TDynamicTextGadgetEnabler ge(*GetGadgetWindow(), this);
    GetGadgetWindow()->HandleMessage(WM_COMMAND_ENABLE,0,TParam2(&ge));
  }
}
Пример #7
0
//
/// Called when the control gadget is inserted in the parent window. Displays the
/// window in its current size and position.
//
/// Override the Inserted() virtual to take the oportunity to make sure that the
/// control window has been created and shown
//
void
TControlGadget::Inserted()
{
  TRACEX(OwlGadget, 1, "TControlGadget::Inserted @" << (void*)this);
  Control->SetParent(GetGadgetWindow());

  if (GetGadgetWindow()->GetHandle())
  {
    if (!Control->GetHandle())
    {
      Control->Create();
    }

    Control->ShowWindow(SW_SHOWNA);
  }
}
Пример #8
0
//
/// Paint the text gadget by painting gadget borders, & then painting text in
/// the InnerRect. Empty or 0 text blanks the gadget.
//
/// Calls TGadget::PaintBorder to paint the border. Calls TGadget::GetInnerRect to
/// calculate the area of the text gadget's rectangle. If the text is left-aligned,
/// Paint calls dc.GetTextExtent to compute the width and height of a line of the
/// text. To set the background color, Paint calls dc.GetSysColor and sets the
/// default background color to face shading (COLOR_BTNFACE). To set the button text
/// color, Paint calls dc.SetTextColor and sets the default button text color to
/// COLOR_BTNTEXT. To draw the text, Paint calls dc.ExtTextOut and passes the
/// parameters ETO_CLIPPED (so the text is clipped to fit the rectangle) and
/// ETO_OPAQUE (so the rectangle is filled with the current background color).
//
void
TTextGadget::Paint(TDC& dc)
{
  PaintBorder(dc);

  TRect  innerRect;
  GetInnerRect(innerRect);

  if (!Font)
    dc.SelectObject(GetGadgetWindow()->GetFont());
  else
    dc.SelectObject(*Font);

  TColor textColor = GetEnabledColor();
  if(!GetEnabled())
    textColor = TColor::Sys3dHilight;

  bool transparent = GetGadgetWindow()->GetFlatStyle() & TGadgetWindow::FlatXPTheme;
  if(!Text){
    if (!transparent)
    {
    TColor color = dc.SetBkColor(TColor::Sys3dFace);
    dc.ExtTextOut(0,0, ETO_OPAQUE, &innerRect, _T(""), 0);
    dc.SetBkColor(color);
  }
  }
  else
  {
    // Create a UI Face object for this button & let it paint the button face
    //
    uint align[] = {DT_LEFT, DT_CENTER, DT_RIGHT};
    uint format =  DT_SINGLELINE | DT_VCENTER | align[Align];
            TUIFace face(innerRect, Text, BkgndColor, format);

     TPoint  dstPt(innerRect.TopLeft());

      dc.SetBkColor(BkgndColor);

     TColor oldTxColor  = dc.SetTextColor(textColor);
    if (!GetEnabled())
      face.Paint(dc, dstPt, TUIFace::Disabled, false, !transparent);
    else
      face.Paint(dc, dstPt, TUIFace::Normal, false, !transparent);
    dc.SetTextColor(oldTxColor);
  }
  dc.RestoreFont();
}
Пример #9
0
//
/// Invalidate the working portion of this gadget--in this case just the
/// InnerRect
///
/// Calls TGadget::GetInnerRect to compute the area of the text for the gadget and
/// then TGadget::InvalidateRect to invalidate the rectangle in the parent window.
void
TTextGadget::Invalidate()
{
  TRect  innerRect;

  GetInnerRect(innerRect);
  bool transparent = GetGadgetWindow()->GetFlatStyle() & TGadgetWindow::FlatXPTheme;
  InvalidateRect(innerRect, transparent); // Erase (redraw background) if transparent.
}
Пример #10
0
//
/// Virtual called after the window holding a gadget has been created
//
void
TControlGadget::Created()
{
  PRECONDITION(GetGadgetWindow());
  PRECONDITION(GetGadgetWindow()->GetHandle());

  // Create control is necessary
  //
  Control->SetParent(GetGadgetWindow());
  if (GetGadgetWindow()->GetHandle() && !Control->GetHandle()) {
    Control->Create();
    Control->ShowWindow(SW_SHOWNA);
  }

  // Register control with the tooltip window (if there's one)
  //
  TTooltip* tooltip = GetGadgetWindow()->GetTooltip();
  if (tooltip) {
    CHECK(tooltip->GetHandle());

    // Register the control with the tooltip
    //
    if (Control->GetHandle()) {
      TToolInfo toolInfo(GetGadgetWindow()->GetHandle(), Control->GetHandle());
      tooltip->AddTool(toolInfo);
    }
  }
}
Пример #11
0
//
/// Set the text for this gadget
//
/// If the text stored in Text is not the same as the new text, SetText deletes the
/// text stored in Text. Then, it sets TextLen to the length of the new string. If
/// no text exists, it sets both Text and TextLen to 0 and then calls Invalidate to
/// invalidate the rectangle.
//
void
TTextGadget::SetText(LPCTSTR text)
{
  // Skip processing if new text is the same as current
  //
  if (text && Text && _tcscmp(text, Text) == 0)
    return;

  delete[] Text;

  if (text) {
    Text = strnewdup(text);
    TextLen = ::_tcslen(Text);
  }
  else {
    Text = 0;
    TextLen = 0;
  }

  if (GetGadgetWindow())
    GetGadgetWindow()->GadgetChangedSize(*this);

  Invalidate();
}
Пример #12
0
//
/// Called when the control gadget is removed from the parent window.
//
/// Override the Remove() virtual to take the oportunity to unparent the
/// control window from the owning Window
//
void
TControlGadget::Removed()
{
  TRACEX(OwlGadget, 1, "TControlGadget::Removed @" << (void*)this);
  Control->ShowWindow(SW_HIDE); // Sirma Update
  Control->SetParent(0);
  // Should we destroy the control at this point??
  // Since it's no longer in the parent's child-list, there's a potential
  // leak. However, the semantics of this function is 'Removed' - therefore
  // one could be removing the control to be reinserted in another 
  // gadgetwindow.

  // Unregister ourself with the tooltip window (if there's one)
  //
  if (GetGadgetWindow() && GetGadgetWindow()->GetHandle()) {
    TTooltip* tooltip = GetGadgetWindow()->GetTooltip();
    if (tooltip) {
      CHECK(tooltip->GetHandle());

      TToolInfo toolInfo(GetGadgetWindow()->GetHandle(), Control->GetHandle());
      tooltip->DeleteTool(toolInfo);
    }
  }
}
Пример #13
0
void
TButtonTextGadget::GetTextSize(TSize& size)
{
  TFont* font = Font;
  if (font == 0)
    font = &(GetGadgetWindow()->GetFont());

  if (font == 0)
    return;

  TEXTMETRIC tm;
  font->GetTextMetrics(tm);

  size.cx += tm.tmAveCharWidth * NumChars;
  size.cy += tm.tmHeight + 2;
}
Пример #14
0
//
/// If (Style & sBitmap) calls TButtonGadget::SetBounds; otherwise calls
/// TGadget::SetBounds to set the boundary of the rectangle, and it (Style &
/// sBitmap) calculates new BitmapOrigin.
//
void
TButtonTextGadget::SetBounds(const TRect& rect)
{
  PRECONDITION(Window);

  if(Style&sBitmap)
    TButtonGadget::SetBounds(rect);
  else
    TGadget::SetBounds(rect);

  if(Style&sBitmap && Style&sText){
    TRect  faceRect, textRect, btnRect;
    GetInnerRect(faceRect);

    Layout(faceRect, textRect, btnRect);

    TSize  bitmapSize = GetCelArray() ? GetCelArray()->CelSize() : GetGadgetWindow()->GetCelArray().CelSize();
    TPoint pt;
    pt.x = btnRect.left + (btnRect.Width() - bitmapSize.cx) / 2;
    pt.y = btnRect.top + (btnRect.Height() - bitmapSize.cy) / 2;
    SetBitmapOrigin(pt);
  }
}
Пример #15
0
//
/// Respond to the virtual call to let this gadget's Window know how big this
/// text gadget wants to be based on the text size.
//
/// If shrink-wrapping is requested, GetDesiredSize returns the size needed to
/// accommodate the borders, margins, and text; otherwise, if shrink-wrapping is not
/// requested, it returns the gadget's current width and height.
//
void
TTextGadget::GetDesiredSize(TSize& size)
{
  TGadget::GetDesiredSize(size);
  TFont* font = Font;
  if (font == 0)
    font = &(GetGadgetWindow()->GetFont());

  if (font == 0)
    return;

  if (ShrinkWrapWidth)
    size.cx += font->GetTextExtent(Text).cx;
  else {
    int  left, right, top, bottom;
    GetOuterSizes(left, right, top, bottom);

    int newW = font->GetMaxWidth() * NumChars;
    size.cx += newW + left + right - Bounds.Width();  // Old bounds already considered
  }

  if (ShrinkWrapHeight)
    size.cy += font->GetHeight() + 2;
}
Пример #16
0
//
/// Paint Text
//
void
TButtonTextGadget::PaintText(TDC& dc, TRect& rect, const tstring& text)
{
  dc.SelectObject(GetFont());

  TColor textColor = TColor::SysBtnText;
  if(!GetEnabled())
    textColor = TColor::Sys3dHilight;
  else if((GetGadgetWindow()->GetFlatStyle()&TGadgetWindow::FlatHotText) && IsHaveMouse())
     textColor = TColor::LtBlue;

   TColor oldTxColor  = dc.SetTextColor(textColor);

  uint format =  DT_SINGLELINE|DT_NOCLIP|DT_END_ELLIPSIS;
  switch(Align){
    case aLeft:
      format |= DT_LEFT;
      break;
    case aRight:
      format |= DT_RIGHT;
      break;
    case aCenter:
      format |= DT_CENTER;
      break;
  }
  switch(LayoutStyle){
    case lTextLeft:
    case lTextRight:
      format |= DT_VCENTER;
      break;
    case lTextTop:
      format |= DT_VCENTER;//DT_BOTTOM;
      break;
    case lTextBottom:
      format |= DT_VCENTER;//DT_TOP;
      break;
  }

  // Create a UI Face object for this button & let it paint the button face
  //
  TPoint  dstPt(rect.TopLeft());

  if (GetButtonState() == Down && GetEnabled() &&
      GetGadgetWindow()->GetFlatStyle()&TGadgetWindow::FlatStandard)
  {
    if(IsHaveMouse())
    {
      if(IsPressed())
      {
        const int dx = (format & DT_CENTER) ? 2 : 1;
        const int dy = (format & DT_VCENTER) ? 2 : 1;
        rect.Offset(dx, dy);
      }
      TUIFace(rect, text, TColor::Sys3dFace,format).Paint(dc, dstPt,
                TUIFace::Normal, true, true);
    }
    else
    {
      TUIFace face(rect, text, TColor::Sys3dFace,format);
      if(GetGadgetWindow()->GadgetGetCaptured()==this)
        face.Paint(dc, dstPt, TUIFace::Normal, true);
      else
        face.Paint(dc, dstPt, TUIFace::Down, IsPressed(), false);
    }
  }
  else
  {
    TUIFace face(rect, text, TColor::Sys3dFace,format);
    if (!GetEnabled())
      face.Paint(dc, dstPt, TUIFace::Disabled, false, false);
    else if (GetButtonState() == Indeterminate)
      face.Paint(dc, dstPt, TUIFace::Indeterm, IsPressed(), false);
    else if (GetButtonState() == Down) // Down and not flat
      face.Paint(dc, dstPt, TUIFace::Down, IsPressed(), false);
    else
      face.Paint(dc, dstPt, TUIFace::Normal, IsPressed(), false);
  }

  dc.SetTextColor(oldTxColor);

  dc.RestoreFont();
}
Пример #17
0
//
/// Returns the effective font used to render the text for this gadget.
/// If no font was passed to the constructor, the font of the gadget window is returned.
//
const TFont&
TButtonTextGadget::GetFont() const
{
  PRECONDITION(GetGadgetWindow());
  return Font ? *Font : GetGadgetWindow()->GetFont();
}