1*a5061eceSAdrien DestuguesDecorator class 2*a5061eceSAdrien Destugues############### 3*a5061eceSAdrien Destugues 4*a5061eceSAdrien DestuguesDecorators provide the actual drawing for a window's looks. 5*a5061eceSAdrien Destugues 6*a5061eceSAdrien Destugues\_ Indicates a protected member function 7*a5061eceSAdrien Destugues 8*a5061eceSAdrien DestuguesMember Functions 9*a5061eceSAdrien Destugues================ 10*a5061eceSAdrien Destugues 11*a5061eceSAdrien DestuguesDecorator(BRect int32 wlook, int32 wfeel, int32 wflags) 12*a5061eceSAdrien Destugues------------------------------------------------------- 13*a5061eceSAdrien Destugues 14*a5061eceSAdrien DestuguesSets up internal variables common to all decorators. 15*a5061eceSAdrien Destugues 16*a5061eceSAdrien Destugues1) Assign parameters to respective data members 17*a5061eceSAdrien Destugues 18*a5061eceSAdrien Destugues~Decorator(void) 19*a5061eceSAdrien Destugues---------------- 20*a5061eceSAdrien Destugues 21*a5061eceSAdrien DestuguesEmpty. 22*a5061eceSAdrien Destugues 23*a5061eceSAdrien Destuguesvoid SetColors(color_set colors) 24*a5061eceSAdrien Destugues-------------------------------- 25*a5061eceSAdrien Destugues 26*a5061eceSAdrien Destuguesvoid SetDriver(DisplayDriver \*driver) 27*a5061eceSAdrien Destugues-------------------------------------- 28*a5061eceSAdrien Destugues 29*a5061eceSAdrien Destuguesvoid SetClose(bool is_down) 30*a5061eceSAdrien Destugues--------------------------- 31*a5061eceSAdrien Destugues 32*a5061eceSAdrien Destuguesvoid SetMinimize(bool is_down) 33*a5061eceSAdrien Destugues------------------------------ 34*a5061eceSAdrien Destugues 35*a5061eceSAdrien Destuguesvoid SetZoom(bool is_down) 36*a5061eceSAdrien Destugues-------------------------- 37*a5061eceSAdrien Destugues 38*a5061eceSAdrien Destuguesvoid SetFlags(int32 wflags) 39*a5061eceSAdrien Destugues--------------------------- 40*a5061eceSAdrien Destugues 41*a5061eceSAdrien Destuguesvoid SetFeel(int32 wfeel) 42*a5061eceSAdrien Destugues------------------------- 43*a5061eceSAdrien Destugues 44*a5061eceSAdrien Destuguesvoid SetLook(int32 wlook) 45*a5061eceSAdrien Destugues------------------------- 46*a5061eceSAdrien Destugues 47*a5061eceSAdrien Destuguesbool GetClose(void) 48*a5061eceSAdrien Destugues------------------- 49*a5061eceSAdrien Destugues 50*a5061eceSAdrien Destuguesbool GetMinimize(void) 51*a5061eceSAdrien Destugues---------------------- 52*a5061eceSAdrien Destugues 53*a5061eceSAdrien Destuguesbool GetZoom(void) 54*a5061eceSAdrien Destugues------------------ 55*a5061eceSAdrien Destugues 56*a5061eceSAdrien Destuguesint32 GetLook(void) 57*a5061eceSAdrien Destugues------------------- 58*a5061eceSAdrien Destugues 59*a5061eceSAdrien Destuguesint32 GetFeel(void) 60*a5061eceSAdrien Destugues------------------- 61*a5061eceSAdrien Destugues 62*a5061eceSAdrien Destuguesint32 GetFlags(void) 63*a5061eceSAdrien Destugues-------------------- 64*a5061eceSAdrien Destugues 65*a5061eceSAdrien Destuguesvoid SetTitle(const char \*string) 66*a5061eceSAdrien Destugues---------------------------------- 67*a5061eceSAdrien Destugues 68*a5061eceSAdrien Destuguesvoid SetFont(SFont \*sf) 69*a5061eceSAdrien Destugues------------------------ 70*a5061eceSAdrien Destugues 71*a5061eceSAdrien DestuguesThese functions work with the internal members common to all 72*a5061eceSAdrien DestuguesDecorators - assigning them and returning them. Additionally, 73*a5061eceSAdrien DestuguesSetTitle() and SetFont() set the clip_font flag to true. 74*a5061eceSAdrien Destugues 75*a5061eceSAdrien Destuguesint32 \_ClipTitle(float width) 76*a5061eceSAdrien Destugues------------------------------ 77*a5061eceSAdrien Destugues 78*a5061eceSAdrien DestuguesClipTitle calculates how much of the title, in characters, can be 79*a5061eceSAdrien Destuguesdisplayed in the given width. 80*a5061eceSAdrien Destugues 81*a5061eceSAdrien Destugues1. Call StringWidth() on the title. 82*a5061eceSAdrien Destugues2. If the string's width is less thanwidth, return the string's 83*a5061eceSAdrien Destugues character count 84*a5061eceSAdrien Destugues3. while the character count to display is > 0 85*a5061eceSAdrien Destugues 86*a5061eceSAdrien Destugues a. calculate the string's width 87*a5061eceSAdrien Destugues b. if the string's width is less than width, return the character count 88*a5061eceSAdrien Destugues c. decrement the character count 89*a5061eceSAdrien Destugues 90*a5061eceSAdrien Destugues4. If the loop completes itself without returning a value, it can't fit, 91*a5061eceSAdrien Destugues so return 0. 92*a5061eceSAdrien Destugues 93*a5061eceSAdrien Destuguesvoid SetFocus(bool is_active) 94*a5061eceSAdrien Destugues----------------------------- 95*a5061eceSAdrien Destugues 96*a5061eceSAdrien DestuguesThis is for handling color states when a window receives or loses the 97*a5061eceSAdrien Destuguesfocus. 98*a5061eceSAdrien Destugues 99*a5061eceSAdrien Destugues1. Set focus flag to whatever is_active is. 100*a5061eceSAdrien Destugues2. call hook function \_SetFocus() 101*a5061eceSAdrien Destugues 102*a5061eceSAdrien Destuguesbool GetFocus(void) 103*a5061eceSAdrien Destugues------------------- 104*a5061eceSAdrien Destugues 105*a5061eceSAdrien DestuguesReturns the focus state held by the decorator 106*a5061eceSAdrien Destugues 107*a5061eceSAdrien Destugues1) Return the focus flag 108*a5061eceSAdrien Destugues 109*a5061eceSAdrien Destuguesint32 \_TitleWidth(void) 110*a5061eceSAdrien Destugues------------------------ 111*a5061eceSAdrien Destugues 112*a5061eceSAdrien DestuguesReturns the character count of the title or 0 if it is NULL. 113*a5061eceSAdrien Destugues 114*a5061eceSAdrien DestuguesVirtual Functions 115*a5061eceSAdrien Destugues================= 116*a5061eceSAdrien Destugues 117*a5061eceSAdrien DestuguesMost of these functions have a default behavior which can be 118*a5061eceSAdrien Destuguesoverridden, but are implemented to handle the more common 119*a5061eceSAdrien Destuguesimplementations. 120*a5061eceSAdrien Destugues 121*a5061eceSAdrien Destuguesvoid MoveBy(float x, float y) 122*a5061eceSAdrien Destugues----------------------------- 123*a5061eceSAdrien Destugues 124*a5061eceSAdrien Destuguesvoid MoveBy(BPoint pt) 125*a5061eceSAdrien Destugues---------------------- 126*a5061eceSAdrien Destugues 127*a5061eceSAdrien DestuguesMove all member rectangles of Decorator by the specified amount. 128*a5061eceSAdrien Destugues 129*a5061eceSAdrien Destuguesvoid ResizeBy(float x, float y) 130*a5061eceSAdrien Destugues------------------------------- 131*a5061eceSAdrien Destugues 132*a5061eceSAdrien Destuguesvoid ResizeBy(BPoint pt) 133*a5061eceSAdrien Destugues------------------------ 134*a5061eceSAdrien Destugues 135*a5061eceSAdrien DestuguesResize the client frame, window frame, and the tab frame (width only) 136*a5061eceSAdrien Destuguesby the specified amount. Button rectangles - close, minimize, and zoom 137*a5061eceSAdrien Destugues- are not modified. 138*a5061eceSAdrien Destugues 139*a5061eceSAdrien Destuguesvoid Draw(BRect r) 140*a5061eceSAdrien Destugues------------------ 141*a5061eceSAdrien Destugues 142*a5061eceSAdrien Destuguesvoid Draw(void) 143*a5061eceSAdrien Destugues--------------- 144*a5061eceSAdrien Destugues 145*a5061eceSAdrien DestuguesMain drawing call which checks the intersection of the rectangle 146*a5061eceSAdrien Destuguespassed to it and draws all items which intersect it. Draw(void) simply 147*a5061eceSAdrien Destuguesperforms drawing calls to draw the entire decorator's footprint area. 148*a5061eceSAdrien Destugues 149*a5061eceSAdrien Destugues1. Check for intersection with BRect which encompasses the decorator's 150*a5061eceSAdrien Destugues footprint and return if no intersection. 151*a5061eceSAdrien Destugues2. Call \_DrawFrame(intersection) 152*a5061eceSAdrien Destugues3. Call \_DrawTab(intersection) 153*a5061eceSAdrien Destugues 154*a5061eceSAdrien Destuguesvoid DrawClose(void) 155*a5061eceSAdrien Destugues-------------------- 156*a5061eceSAdrien Destugues 157*a5061eceSAdrien Destuguesprotected: void \_DrawClose(BRect r) 158*a5061eceSAdrien Destugues------------------------------------ 159*a5061eceSAdrien Destugues 160*a5061eceSAdrien Destuguesvoid DrawMinimize(void) 161*a5061eceSAdrien Destugues----------------------- 162*a5061eceSAdrien Destugues 163*a5061eceSAdrien Destuguesprotected: void \_DrawMinimize(BRect r) 164*a5061eceSAdrien Destugues--------------------------------------- 165*a5061eceSAdrien Destugues 166*a5061eceSAdrien Destuguesvoid DrawZoom(void) 167*a5061eceSAdrien Destugues------------------- 168*a5061eceSAdrien Destugues 169*a5061eceSAdrien Destuguesprotected: void \_DrawZoom(BRect r) 170*a5061eceSAdrien Destugues----------------------------------- 171*a5061eceSAdrien Destugues 172*a5061eceSAdrien DestuguesEach of these is designed to utilize their respective button 173*a5061eceSAdrien Destuguesrectangles. The public (void) versions simply call the internal 174*a5061eceSAdrien Destuguesprotected ones with the button rectangle. These protected versions 175*a5061eceSAdrien Destuguesare, by default, empty. The rectangle passed to them is the invalid 176*a5061eceSAdrien Destuguesarea to be drawn, which is not necessarily the entire button's 177*a5061eceSAdrien Destuguesrectangle. 178*a5061eceSAdrien Destugues 179*a5061eceSAdrien Destuguesvoid DrawFrame(void) 180*a5061eceSAdrien Destugues-------------------- 181*a5061eceSAdrien Destugues 182*a5061eceSAdrien Destuguesprotected: void \_DrawFrame(BRect r) 183*a5061eceSAdrien Destugues------------------------------------ 184*a5061eceSAdrien Destugues 185*a5061eceSAdrien DestuguesDraws the frame, if any. The public version amounts to 186*a5061eceSAdrien Destugues\_DrawFrame(framerect). The protected version is expected to not cover 187*a5061eceSAdrien Destuguesup the client frame when drawing. Any drawing within the clientrect 188*a5061eceSAdrien Destuguesmember will end up being drawn over by the window's child views. 189*a5061eceSAdrien Destugues 190*a5061eceSAdrien Destuguesvoid DrawTab(void) 191*a5061eceSAdrien Destugues------------------ 192*a5061eceSAdrien Destugues 193*a5061eceSAdrien Destuguesprotected: void \_DrawTab(BRect r) 194*a5061eceSAdrien Destugues---------------------------------- 195*a5061eceSAdrien Destugues 196*a5061eceSAdrien DestuguesDraws the window's tab, if any. DrawTab() amounts to 197*a5061eceSAdrien Destugues\_DrawTab(tabrect). If window titles are displayed, the \_DrawTitle 198*a5061eceSAdrien Destuguescall is expected to be made here. Button-drawing calls, assuming that 199*a5061eceSAdrien Destuguesa window's buttons are in the tab, should be made here, as well. 200*a5061eceSAdrien Destugues 201*a5061eceSAdrien Destuguesvoid DrawTitle(void) 202*a5061eceSAdrien Destugues-------------------- 203*a5061eceSAdrien Destugues 204*a5061eceSAdrien Destuguesprotected: void \_DrawTitle(BRect r) 205*a5061eceSAdrien Destugues------------------------------------ 206*a5061eceSAdrien Destugues 207*a5061eceSAdrien DestuguesThese cause the window's title to be drawn. DrawTitle() amounts to 208*a5061eceSAdrien Destugues\_DrawTitle(titlerect). 209*a5061eceSAdrien Destugues 210*a5061eceSAdrien Destuguesvoid \_SetFocus(void) 211*a5061eceSAdrien Destugues--------------------- 212*a5061eceSAdrien Destugues 213*a5061eceSAdrien DestuguesThis hook function is primarily used to change colors used when a 214*a5061eceSAdrien Destugueswindow changes focus states and is called immediately after the state 215*a5061eceSAdrien Destuguesis changed. If, for example, a decorator does not use OpenBeOS' GUI 216*a5061eceSAdrien Destuguescolor set, it would change its drawing colors to reflect the change in 217*a5061eceSAdrien Destuguesfocus. 218*a5061eceSAdrien Destugues 219*a5061eceSAdrien DestuguesSRegion GetFootprint(void) 220*a5061eceSAdrien Destugues-------------------------- 221*a5061eceSAdrien Destugues 222*a5061eceSAdrien DestuguesThis returns the "footprint" of the decorator, i.e. the area which is 223*a5061eceSAdrien Destuguesoccupied by the window which is is the border surrounding the main 224*a5061eceSAdrien Destuguesclient rectangle. It is possible to have oddly-shaped window borders, 225*a5061eceSAdrien Destugueslike ellipses and circles, but the resulting performance hit would 226*a5061eceSAdrien Destuguesreduce the said decorator to a novelty and not something useable. All 227*a5061eceSAdrien Destuguesversions are to construct an SRegion which the border occupies. This 228*a5061eceSAdrien Destuguesfootprint is permitted to include the client rectangle area, but this 229*a5061eceSAdrien Destuguesarea must not be actually drawn upon by the decorator itself. The 230*a5061eceSAdrien Destuguesdefault version returns the frame which encompasses all other 231*a5061eceSAdrien Destuguesrectangles - the "frame" member which belongs to its window border. 232*a5061eceSAdrien Destugues 233*a5061eceSAdrien Destuguesclick_type Clicked(BPoint pt, int32 buttons, int32 modifiers) 234*a5061eceSAdrien Destugues------------------------------------------------------------- 235*a5061eceSAdrien Destugues 236*a5061eceSAdrien DestuguesClicked() performs hit testing for the decorator, given input 237*a5061eceSAdrien Destuguesconditions. This function is required by ALL subclasses expecting to 238*a5061eceSAdrien Destuguesdo more than display itself. The return type will cause the server to 239*a5061eceSAdrien Destuguestake the appropriate actions, such as close the window, get ready to 240*a5061eceSAdrien Destuguesmove it, etc. 241*a5061eceSAdrien Destugues 242*a5061eceSAdrien Destugues 243*a5061eceSAdrien DestuguesBRect SlideTab(float dx, dy=0) 244*a5061eceSAdrien Destugues------------------------------ 245*a5061eceSAdrien Destugues 246*a5061eceSAdrien DestuguesSlideTab is implemented only for those decorators which allow the user 247*a5061eceSAdrien Destuguesto somehow slide the tab (if there is one) along the window. 248*a5061eceSAdrien DestuguesCurrently, only the horizontal direction is supported. It returns the 249*a5061eceSAdrien Destuguesrectangle of the invalid region which needs redrawn as a result of the 250*a5061eceSAdrien Destuguesslide. 251*a5061eceSAdrien Destugues 252*a5061eceSAdrien DestuguesExported C Functions 253*a5061eceSAdrien Destugues==================== 254*a5061eceSAdrien Destugues 255*a5061eceSAdrien Destuguesextern "C" Decorator \*create_decorator(BRect frame, int32 wlook, int32 wfeel, int32 wflags) 256*a5061eceSAdrien Destugues-------------------------------------------------------------------------------------------- 257*a5061eceSAdrien Destugues 258*a5061eceSAdrien DestuguesRequired export function which simply allocates an instance of the 259*a5061eceSAdrien Destuguesdecorator and returns it. 260*a5061eceSAdrien Destugues 261*a5061eceSAdrien Destuguesextern "C" float get_decorator_version(void) 262*a5061eceSAdrien Destugues-------------------------------------------- 263*a5061eceSAdrien Destugues 264*a5061eceSAdrien DestuguesThis should, for now, return 1.00. 265*a5061eceSAdrien Destugues 266*a5061eceSAdrien DestuguesEnumerated Types 267*a5061eceSAdrien Destugues================ 268*a5061eceSAdrien Destugues 269*a5061eceSAdrien Destuguesclick_type 270*a5061eceSAdrien Destugues---------- 271*a5061eceSAdrien Destugues 272*a5061eceSAdrien Destugues- CLICK_NONE 273*a5061eceSAdrien Destugues- CLICK_ZOOM 274*a5061eceSAdrien Destugues- CLICK_CLOSE 275*a5061eceSAdrien Destugues- CLICK_MINIMIZE 276*a5061eceSAdrien Destugues- CLICK_TAB 277*a5061eceSAdrien Destugues- CLICK_MOVE 278*a5061eceSAdrien Destugues- CLICK_MOVETOBACK 279*a5061eceSAdrien Destugues- CLICK_MOVETOFRONT 280*a5061eceSAdrien Destugues- CLICK_RESIZE 281*a5061eceSAdrien Destugues- CLICK_RESIZE_L 282*a5061eceSAdrien Destugues- CLICK_RESIZE_T 283*a5061eceSAdrien Destugues- CLICK_RESIZE_R 284*a5061eceSAdrien Destugues- CLICK_RESIZE_B 285*a5061eceSAdrien Destugues- CLICK_RESIZE_LT 286*a5061eceSAdrien Destugues- CLICK_RESIZE_RT 287*a5061eceSAdrien Destugues- CLICK_RESIZE_LB 288*a5061eceSAdrien Destugues- CLICK_RESIZE_RB 289*a5061eceSAdrien Destugues 290