Home | History | Annotate | Download | only in views
      1 
      2 /*
      3  * Copyright 2006 The Android Open Source Project
      4  *
      5  * Use of this source code is governed by a BSD-style license that can be
      6  * found in the LICENSE file.
      7  */
      8 
      9 
     10 #ifndef SkWindow_DEFINED
     11 #define SkWindow_DEFINED
     12 
     13 #include "SkView.h"
     14 #include "SkBitmap.h"
     15 #include "SkMatrix.h"
     16 #include "SkRegion.h"
     17 #include "SkEvent.h"
     18 #include "SkKey.h"
     19 #include "SkTDArray.h"
     20 
     21 #ifdef SK_BUILD_FOR_WINCEx
     22     #define SHOW_FPS
     23 #endif
     24 //#define USE_GX_SCREEN
     25 
     26 class SkCanvas;
     27 
     28 class SkOSMenu;
     29 
     30 class SkWindow : public SkView {
     31 public:
     32             SkWindow();
     33     virtual ~SkWindow();
     34 
     35     const SkBitmap& getBitmap() const { return fBitmap; }
     36 
     37     void    setConfig(SkBitmap::Config);
     38     void    resize(int width, int height, SkBitmap::Config config = SkBitmap::kNo_Config);
     39     void    eraseARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b);
     40     void    eraseRGB(U8CPU r, U8CPU g, U8CPU b);
     41 
     42     bool    isDirty() const { return !fDirtyRgn.isEmpty(); }
     43     bool    update(SkIRect* updateArea, SkCanvas* = NULL);
     44     // does not call through to onHandleInval(), but does force the fDirtyRgn
     45     // to be wide open. Call before update() to ensure we redraw everything.
     46     void    forceInvalAll();
     47     // return the bounds of the dirty/inval rgn, or [0,0,0,0] if none
     48     const SkIRect& getDirtyBounds() const { return fDirtyRgn.getBounds(); }
     49 
     50     bool    handleClick(int x, int y, Click::State, void* owner = NULL);
     51     bool    handleChar(SkUnichar);
     52     bool    handleKey(SkKey);
     53     bool    handleKeyUp(SkKey);
     54 
     55     void    addMenu(SkOSMenu*);
     56     const SkTDArray<SkOSMenu*>* getMenus() { return &fMenus; }
     57 
     58     const char* getTitle() const { return fTitle.c_str(); }
     59     void    setTitle(const char title[]);
     60 
     61     const SkMatrix& getMatrix() const { return fMatrix; }
     62     void    setMatrix(const SkMatrix&);
     63     void    preConcat(const SkMatrix&);
     64     void    postConcat(const SkMatrix&);
     65 
     66     virtual void onPDFSaved(const char title[], const char desc[],
     67         const char path[]) {}
     68 protected:
     69     virtual bool onEvent(const SkEvent&);
     70     virtual bool onDispatchClick(int x, int y, Click::State, void* owner);
     71     // called if part of our bitmap is invalidated
     72     virtual void onHandleInval(const SkIRect&);
     73     virtual bool onHandleChar(SkUnichar);
     74     virtual bool onHandleKey(SkKey);
     75     virtual bool onHandleKeyUp(SkKey);
     76     virtual void onAddMenu(const SkOSMenu*) {};
     77     virtual void onUpdateMenu(const SkOSMenu*) {};
     78     virtual void onSetTitle(const char title[]) {}
     79 
     80     // overrides from SkView
     81     virtual bool handleInval(const SkRect*);
     82     virtual bool onGetFocusView(SkView** focus) const;
     83     virtual bool onSetFocusView(SkView* focus);
     84 
     85 private:
     86     SkBitmap::Config    fConfig;
     87     SkBitmap    fBitmap;
     88     SkRegion    fDirtyRgn;
     89 
     90     SkTDArray<Click*>       fClicks; // to track clicks
     91 
     92     SkTDArray<SkOSMenu*>    fMenus;
     93 
     94     SkView* fFocusView;
     95     bool    fWaitingOnInval;
     96 
     97     SkString    fTitle;
     98     SkMatrix    fMatrix;
     99 
    100     typedef SkView INHERITED;
    101 };
    102 
    103 ///////////////////////////////////////////////////////////
    104 
    105 #ifdef SK_USE_WXWIDGETS
    106     #include "SkOSWindow_wxwidgets.h"
    107 #elif defined(SK_BUILD_FOR_MAC)
    108     #include "SkOSWindow_Mac.h"
    109 #elif defined(SK_BUILD_FOR_WIN)
    110     #include "SkOSWindow_Win.h"
    111 #elif defined(SK_BUILD_FOR_ANDROID)
    112     #include "SkOSWindow_Android.h"
    113 #elif defined(SK_BUILD_FOR_UNIX)
    114   #include "SkOSWindow_Unix.h"
    115 #elif defined(SK_BUILD_FOR_SDL)
    116     #include "SkOSWindow_SDL.h"
    117 #elif defined(SK_BUILD_FOR_IOS)
    118     #include "SkOSWindow_iOS.h"
    119 #endif
    120 
    121 #endif
    122 
    123