1/* Copyright (C) 2010 Apple Inc. All rights reserved. 2 * 3 * Redistribution and use in source and binary forms, with or without 4 * modification, are permitted provided that the following conditions 5 * are met: 6 * 1. Redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer. 8 * 2. Redistributions in binary form must reproduce the above copyright 9 * notice, this list of conditions and the following disclaimer in the 10 * documentation and/or other materials provided with the distribution. 11 * 12 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 13 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 14 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 16 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 17 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 18 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 19 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 20 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 22 * THE POSSIBILITY OF SUCH DAMAGE. 23 */ 24 25#include "WindowedPluginTest.h" 26 27#include "PluginObject.h" 28 29using namespace std; 30 31// Just fills its window with some gradients 32 33class DrawsGradient : public WindowedPluginTest { 34public: 35 DrawsGradient(NPP, const string& identifier); 36 37private: 38 void paint(HDC) const; 39 40 LRESULT onPaint(WPARAM, LPARAM, bool& handled); 41 LRESULT onPrintClient(WPARAM, LPARAM, bool& handled); 42 43 virtual LRESULT wndProc(UINT message, WPARAM, LPARAM, bool& handled); 44}; 45 46static PluginTest::Register<DrawsGradient> registrar("draws-gradient"); 47 48DrawsGradient::DrawsGradient(NPP npp, const string& identifier) 49 : WindowedPluginTest(npp, identifier) 50{ 51} 52 53LRESULT DrawsGradient::wndProc(UINT message, WPARAM wParam, LPARAM lParam, bool& handled) 54{ 55 LRESULT result = 0; 56 57 switch (message) { 58 case WM_PAINT: 59 result = onPaint(wParam, lParam, handled); 60 break; 61 case WM_PRINTCLIENT: 62 result = onPrintClient(wParam, lParam, handled); 63 break; 64 default: 65 handled = false; 66 } 67 68 return result; 69} 70 71LRESULT DrawsGradient::onPaint(WPARAM, LPARAM, bool& handled) 72{ 73 PAINTSTRUCT paintStruct; 74 HDC dc = ::BeginPaint(window(), &paintStruct); 75 if (!dc) 76 return 0; 77 78 paint(dc); 79 ::EndPaint(window(), &paintStruct); 80 81 handled = true; 82 return 0; 83} 84 85LRESULT DrawsGradient::onPrintClient(WPARAM wParam, LPARAM, bool& handled) 86{ 87 paint(reinterpret_cast<HDC>(wParam)); 88 89 handled = true; 90 return 0; 91} 92 93void DrawsGradient::paint(HDC dc) const 94{ 95 RECT clientRect; 96 if (!::GetClientRect(window(), &clientRect)) 97 return; 98 99 TRIVERTEX vertices[] = { 100 // Upper-left: green 101 { clientRect.left, clientRect.top, 0, 0xff00, 0, 0 }, 102 // Upper-right: blue 103 { clientRect.right, clientRect.top, 0, 0, 0xff00, 0 }, 104 // Lower-left: yellow 105 { clientRect.left, clientRect.bottom, 0xff00, 0xff00, 0, 0 }, 106 // Lower-right: red 107 { clientRect.right, clientRect.bottom, 0xff00, 0, 0, 0 }, 108 }; 109 110 GRADIENT_TRIANGLE mesh[] = { 111 // Upper-left triangle 112 { 0, 1, 2 }, 113 // Lower-right triangle 114 { 1, 2, 3 }, 115 }; 116 117 ::GradientFill(dc, vertices, _countof(vertices), mesh, _countof(mesh), GRADIENT_FILL_TRIANGLE); 118} 119