| OLD | NEW |
| (Empty) |
| 1 // Copyright 2006-2009 Google Inc. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 // ======================================================================== | |
| 15 // | |
| 16 | |
| 17 #include "omaha/ui/uilib/static_line.h" | |
| 18 #include "omaha/ui/uilib/node.h" | |
| 19 #include "omaha/ui/uilib/static_ex.h" | |
| 20 | |
| 21 | |
| 22 StaticLine::StaticLine() | |
| 23 : base_line_(0), | |
| 24 height_(0), | |
| 25 elipses_(false) { | |
| 26 } | |
| 27 | |
| 28 | |
| 29 StaticLine::~StaticLine() { | |
| 30 } | |
| 31 | |
| 32 | |
| 33 int StaticLine::AdjustHeight(int height) { | |
| 34 height_ = std::max(height_, height); | |
| 35 return height_; | |
| 36 } | |
| 37 | |
| 38 | |
| 39 int StaticLine::AdjustBaseLine(int base_line) { | |
| 40 base_line_ = std::max(base_line_, base_line); | |
| 41 return base_line_; | |
| 42 } | |
| 43 | |
| 44 | |
| 45 void StaticLine::AddNode(Node* node, int start, int length, int height, | |
| 46 int base_line, int width) { | |
| 47 nodes_.push_back(Nodes(node, start, length, height, base_line, width)); | |
| 48 AdjustHeight(height); | |
| 49 AdjustBaseLine(base_line); | |
| 50 } | |
| 51 | |
| 52 | |
| 53 int StaticLine::Paint(HDC hdc, int left, int right, int y, DWORD window_style, | |
| 54 int ellipsis) { | |
| 55 int old_bk_mode = SetBkMode(hdc, TRANSPARENT); | |
| 56 bool single_line = (window_style & SS_LEFTNOWORDWRAP) != 0; | |
| 57 | |
| 58 size_t size = nodes_.size(); | |
| 59 for (size_t i = 0; i < size; i++) { | |
| 60 Node* node = nodes_[i].node; | |
| 61 int start = nodes_[i].start; | |
| 62 int length = nodes_[i].length; | |
| 63 int base_line = nodes_[i].base_line; | |
| 64 int width = nodes_[i].width; | |
| 65 | |
| 66 CString text(static_cast<LPCTSTR>(node->node_text()) + start, length); | |
| 67 if (elipses_ && (i == (size - 1))) | |
| 68 text += "..."; | |
| 69 | |
| 70 CRect rect(left, y + base_line_ - base_line, left + width, y + height_); | |
| 71 if (single_line) | |
| 72 rect.right = right; | |
| 73 | |
| 74 nodes_[i].rect = rect; | |
| 75 | |
| 76 const NodeState& nodeState = node->node_state(); | |
| 77 HFONT font = nodeState.GetFont(); | |
| 78 if (!font) | |
| 79 return height_; | |
| 80 | |
| 81 HFONT old_font = static_cast<HFONT>(SelectObject(hdc, font)); | |
| 82 COLORREF old_text_color = SetTextColor(hdc, nodeState.text_color()); | |
| 83 | |
| 84 DWORD draw_style = 0; | |
| 85 draw_style = DT_LEFT | DT_NOCLIP | DT_NOPREFIX | DT_SINGLELINE; | |
| 86 if (ellipsis && (i == (size - 1))) | |
| 87 draw_style = draw_style | ellipsis; | |
| 88 | |
| 89 DrawText(hdc, text, text.GetLength(), rect, draw_style); | |
| 90 left += width; | |
| 91 | |
| 92 SetTextColor(hdc, old_text_color); | |
| 93 if (old_font) | |
| 94 SelectObject(hdc, old_font); | |
| 95 } | |
| 96 | |
| 97 SetBkMode(hdc, old_bk_mode); | |
| 98 return height_; | |
| 99 } | |
| 100 | |
| 101 | |
| 102 int StaticLine::HitTest(CPoint point) { | |
| 103 size_t size = nodes_.size(); | |
| 104 for (size_t i = 0; i < size; i++) { | |
| 105 if (nodes_[i].node->node_state().IsURL()) { | |
| 106 if (nodes_[i].rect.PtInRect(point)) { | |
| 107 return static_cast<int>(i); | |
| 108 } | |
| 109 } | |
| 110 } | |
| 111 | |
| 112 return -1; | |
| 113 } | |
| 114 | |
| 115 | |
| 116 bool StaticLine::IsUrlUnderMouse(CPoint point, CString* action) { | |
| 117 int index = HitTest(point); | |
| 118 if (index >= 0 && action) { | |
| 119 *action = nodes_[index].node->node_state().url(); | |
| 120 } | |
| 121 return (index >= 0); | |
| 122 } | |
| OLD | NEW |