00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef ARCHON_DISPLAY_CONTEXT_H
00021 #define ARCHON_DISPLAY_CONTEXT_H
00022
00023 #include <stdexcept>
00024 #include <string>
00025
00026 #include <archon/util/exception.H>
00027 #include <archon/util/ref.H>
00028 #include <archon/display/visual.H>
00029 #include <archon/display/drawable.H>
00030
00031 namespace Archon
00032 {
00033 namespace Display
00034 {
00035 using namespace std;
00036 using namespace Utilities;
00037
00038
00039
00040
00041
00042 struct Visual;
00043 struct Drawable;
00044
00045
00046 struct ContextAlreadyBoundException: Exception
00047 {
00048 ContextAlreadyBoundException(string l): Exception(l) {}
00049 };
00050
00051 struct NestedBindingException: Exception
00052 {
00053 NestedBindingException(string l): Exception(l) {}
00054 };
00055
00056
00057 struct Bind;
00058
00078 struct Context: virtual RefObjectBase
00079 {
00086 virtual Ref<Visual> getVisual() = 0;
00087
00093 virtual bool isDirect() = 0;
00094
00095 private:
00096 friend struct Bind;
00097 virtual void bind(const Ref<Drawable> &, bool block)
00098 throw(ContextAlreadyBoundException, NestedBindingException,
00099 invalid_argument) = 0;
00100 virtual void unbind() = 0;
00101 };
00102
00103
00129 struct Bind
00130 {
00142 Bind(const Ref<Context> &c, const Ref<Drawable> &d, bool block = true)
00143 throw(ContextAlreadyBoundException, NestedBindingException, invalid_argument)
00144 {
00145 aquire(c, d, block);
00146 }
00147
00148 ~Bind() { release(); }
00149
00181 void aquire(const Ref<Context> &c, const Ref<Drawable> &d, bool block = true)
00182 throw(ContextAlreadyBoundException, NestedBindingException, invalid_argument)
00183 {
00184 if(context) release();
00185 c->bind(d, block);
00186 context = c;
00187 }
00188
00192 void release()
00193 {
00194 if(!context) return;
00195 context->unbind();
00196 context.reset();
00197 }
00198
00199 private:
00200 Ref<Context> context;
00201 };
00202 }
00203 }
00204
00205 #endif // ARCHON_DISPLAY_CONTEXT_H