mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-04 11:26:09 +00:00
Add preliminary support for editting items in toolbars.
This commit is contained in:
parent
6b5de30de6
commit
2fedc0af97
@ -2153,8 +2153,6 @@ _XfeButtonLeave(Widget w,XEvent * event,char ** params,Cardinal * nparams)
|
||||
/* extern */ void
|
||||
_XfeButtonMotion(Widget w,XEvent * event,char ** params,Cardinal * nparams)
|
||||
{
|
||||
XfeButtonPart * bp = _XfeButtonPart(w);
|
||||
|
||||
/* Make sure a button is not being pressed */
|
||||
if (XfeEventGetModifiers(event) & Button1Mask)
|
||||
{
|
||||
@ -2238,6 +2236,14 @@ _XfeButtonArm(Widget w,XEvent * event,char ** params,Cardinal * nparams)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Look for a Edit() action */
|
||||
if (_XfeLabelAcceptEditEvent(w,event,!accept_event))
|
||||
{
|
||||
_XfeLabelEdit(w,event,params,nparams);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* Make sure the event is accepted */
|
||||
if (!accept_event)
|
||||
{
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
|
||||
#include <Xfe/LabelP.h>
|
||||
#include <Xfe/ToolBar.h>
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
/* */
|
||||
@ -33,7 +34,7 @@
|
||||
/*----------------------------------------------------------------------*/
|
||||
#define MESSAGE1 "Widget is not a XfeLabel."
|
||||
#define MESSAGE2 "If XmNtruncateLabel is true, XmNtruncateProc cannot be NULL."
|
||||
|
||||
#define MESSAGE3 "Cannot edit label because parent is not XfeToolBar."
|
||||
|
||||
#define INSENSITIVE_OFFSET 1
|
||||
|
||||
@ -74,7 +75,7 @@ static GC GetSelectionGC (Widget);
|
||||
/* Misc XfeLabel functions */
|
||||
/* */
|
||||
/*----------------------------------------------------------------------*/
|
||||
static XmString CreateTruncatedString (Widget);
|
||||
static XmString CreateTruncatedString (Widget);
|
||||
static void InvokeSelectionChangedCallback (Widget,XEvent *);
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
@ -182,7 +183,18 @@ static XtResource resources[] =
|
||||
(XtPointer) None
|
||||
},
|
||||
|
||||
/* Force buffer type to XmBUFFER_NONE */
|
||||
/* Edit resources */
|
||||
{
|
||||
XmNeditModifiers,
|
||||
XmCEditModifiers,
|
||||
XmRModifiers,
|
||||
sizeof(Modifiers),
|
||||
XtOffsetOf(XfeLabelRec , xfe_label . edit_modifiers),
|
||||
XmRImmediate,
|
||||
(XtPointer) None
|
||||
},
|
||||
|
||||
/* Force XmNbufferType to XmBUFFER_SHARED */
|
||||
{
|
||||
XmNbufferType,
|
||||
XmCBufferType,
|
||||
@ -193,6 +205,7 @@ static XtResource resources[] =
|
||||
(XtPointer) XmBUFFER_SHARED
|
||||
},
|
||||
|
||||
/* Force XmNtraversalOn to False */
|
||||
{
|
||||
XmNtraversalOn,
|
||||
XmCTraversalOn,
|
||||
@ -202,6 +215,8 @@ static XtResource resources[] =
|
||||
XmRImmediate,
|
||||
(XtPointer) False
|
||||
},
|
||||
|
||||
/* Force XmNhighlightThickness to 0 */
|
||||
{
|
||||
XmNhighlightThickness,
|
||||
XmCHighlightThickness,
|
||||
@ -220,7 +235,7 @@ static XtResource resources[] =
|
||||
/*----------------------------------------------------------------------*/
|
||||
static XtActionsRec actions[] =
|
||||
{
|
||||
{ "Select", _XfeLabelSelect },
|
||||
{ "Btn1Down", _XfeLabelBtn1Down },
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
@ -959,7 +974,7 @@ InvokeSelectionChangedCallback(Widget w,XEvent * event)
|
||||
/* */
|
||||
/*----------------------------------------------------------------------*/
|
||||
/* extern */ void
|
||||
_XfeLabelSelect(Widget w,XEvent * event,char ** params,Cardinal * nparams)
|
||||
_XfeLabelBtn1Down(Widget w,XEvent * event,char ** params,Cardinal * nparams)
|
||||
{
|
||||
XfeLabelPart * lp = _XfeLabelPart(w);
|
||||
|
||||
@ -969,11 +984,49 @@ _XfeLabelSelect(Widget w,XEvent * event,char ** params,Cardinal * nparams)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Look for modifiers that matches the selection modifiers */
|
||||
/* Look for modifiers that matche the selection modifiers */
|
||||
if (_XfeLabelAcceptSelectionEvent(w,event,True))
|
||||
{
|
||||
_XfeLabelSetSelected(w,event,!lp->selected,True);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* Look for modifiers that matche the edit modifiers */
|
||||
if (_XfeLabelAcceptEditEvent(w,event,True))
|
||||
{
|
||||
_XfeLabelEdit(w,event,params,nparams);
|
||||
}
|
||||
}
|
||||
/*----------------------------------------------------------------------*/
|
||||
/* extern */ void
|
||||
_XfeLabelSelect(Widget w,XEvent * event,char ** params,Cardinal * nparams)
|
||||
{
|
||||
XfeLabelPart * lp = _XfeLabelPart(w);
|
||||
|
||||
_XfeLabelSetSelected(w,event,!lp->selected,True);
|
||||
}
|
||||
/*----------------------------------------------------------------------*/
|
||||
/* extern */ void
|
||||
_XfeLabelEdit(Widget w,XEvent * event,char ** params,Cardinal * nparams)
|
||||
{
|
||||
XfeLabelPart * lp = _XfeLabelPart(w);
|
||||
|
||||
/* Make sure parent is XfeToolBar */
|
||||
if (!XfeIsToolBar(_XfeParent(w)))
|
||||
{
|
||||
_XfeWarning(w,MESSAGE3);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* Ask the toolbar to edit us */
|
||||
XfeToolBarEditItem(_XfeParent(w),
|
||||
w,
|
||||
lp->label_rect.x,
|
||||
lp->label_rect.y,
|
||||
lp->label_rect.width,
|
||||
lp->label_rect.height);
|
||||
}
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
@ -1011,6 +1064,35 @@ _XfeLabelAcceptSelectionEvent(Widget w,XEvent * event,Boolean inside_label)
|
||||
return result;
|
||||
}
|
||||
/*----------------------------------------------------------------------*/
|
||||
/* extern */ Boolean
|
||||
_XfeLabelAcceptEditEvent(Widget w,XEvent * event,Boolean inside_label)
|
||||
{
|
||||
XfeLabelPart * lp = _XfeLabelPart(w);
|
||||
Boolean result = False;
|
||||
|
||||
/* Look for modifiers that matches the edit modifiers */
|
||||
if ((XfeEventGetModifiers(event) & lp->edit_modifiers) ||
|
||||
(lp->edit_modifiers == AnyModifier))
|
||||
{
|
||||
/* Make sure the event's x,y occured inside the label if needed */
|
||||
if (inside_label)
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
|
||||
/* Determine if the pointer is in the label */
|
||||
result = (XfeEventGetXY(event,&x,&y) &&
|
||||
XfePointInRect(&lp->label_rect,x,y));
|
||||
}
|
||||
else
|
||||
{
|
||||
result = True;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
/*----------------------------------------------------------------------*/
|
||||
/* extern */ void
|
||||
_XfeLabelSetSelected(Widget w,
|
||||
XEvent * event,
|
||||
@ -1168,8 +1250,6 @@ XfeLabelSetStringPSZ(Widget w,String psz_label)
|
||||
/* extern */ void
|
||||
XfeLabelSetSelected(Widget w,Boolean selected)
|
||||
{
|
||||
XfeLabelPart * lp = _XfeLabelPart(w);
|
||||
|
||||
assert( XfeIsLabel(w) );
|
||||
|
||||
_XfeLabelSetSelected(w,NULL,selected,False);
|
||||
|
@ -89,6 +89,9 @@ typedef struct _XfeLabelPart
|
||||
Pixel selection_color; /* Selection color */
|
||||
Modifiers selection_modifiers; /* Selection mod */
|
||||
|
||||
/* Edit resources */
|
||||
Modifiers edit_modifiers; /* Edit mod */
|
||||
|
||||
/* Private Data Members */
|
||||
GC label_GC; /* Label gc */
|
||||
GC insensitive_top_GC; /* Insens top gc */
|
||||
@ -153,8 +156,14 @@ _XfeLabelGetSelectionGC (Widget w);
|
||||
/* */
|
||||
/*----------------------------------------------------------------------*/
|
||||
extern void
|
||||
_XfeLabelBtn1Down (Widget,XEvent *,char **,Cardinal *);
|
||||
/*----------------------------------------------------------------------*/
|
||||
extern void
|
||||
_XfeLabelSelect (Widget,XEvent *,char **,Cardinal *);
|
||||
/*----------------------------------------------------------------------*/
|
||||
extern void
|
||||
_XfeLabelEdit (Widget,XEvent *,char **,Cardinal *);
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
/* */
|
||||
@ -166,6 +175,11 @@ _XfeLabelAcceptSelectionEvent (Widget w,
|
||||
XEvent * event,
|
||||
Boolean inside_label);
|
||||
/*----------------------------------------------------------------------*/
|
||||
extern Boolean
|
||||
_XfeLabelAcceptEditEvent (Widget w,
|
||||
XEvent * event,
|
||||
Boolean inside_label);
|
||||
/*----------------------------------------------------------------------*/
|
||||
extern void
|
||||
_XfeLabelSetSelected (Widget w,
|
||||
XEvent * event,
|
||||
|
@ -165,6 +165,7 @@
|
||||
#define XmNdragThreshold "dragThreshold"
|
||||
#define XmNdrawCascadeArrow "drawCascadeArrow"
|
||||
#define XmNdynamicIndicator "dynamicIndicator"
|
||||
#define XmNeditModifiers "editModifiers"
|
||||
#define XmNemulateMotif "emulateMotif"
|
||||
#define XmNendPercent "endPercent"
|
||||
#define XmNfillOnEnter "fillOnEnter"
|
||||
@ -375,6 +376,7 @@
|
||||
#define XmCDrawCascadeArrow "DrawCascadeArrow"
|
||||
#define XmCDropping "Dropping"
|
||||
#define XmCDynamicIndicator "DynamicIndicator"
|
||||
#define XmCEditModifiers "EditModifiers"
|
||||
#define XmCEmulateMotif "EmulateMotif"
|
||||
#define XmCEndPercent "EndPercent"
|
||||
#define XmCFillOnEnter "FillOnEnter"
|
||||
|
@ -35,6 +35,7 @@
|
||||
|
||||
#include <Xm/Separator.h>
|
||||
#include <Xm/SeparatoG.h>
|
||||
#include <Xm/TextF.h>
|
||||
|
||||
#define MESSAGE1 "Widget is not an XfeToolBar."
|
||||
#define MESSAGE2 "XfeToolbar can only have XfeButton & XmSeparator children."
|
||||
@ -43,11 +44,13 @@
|
||||
#define MESSAGE5 "XmNindicatorPosition is set but XmNnumChildren is 0."
|
||||
#define MESSAGE6 "XmNindicatorPosition is less than 0."
|
||||
#define MESSAGE7 "XmNindicatorPosition is more than XmNnumChildren."
|
||||
#define MESSAGE8 "No valid edit text found in toolbar."
|
||||
|
||||
#define DEFAULT_MAX_CHILD_HEIGHT 0
|
||||
#define DEFAULT_MAX_CHILD_WIDTH 0
|
||||
|
||||
#define INDICATOR_NAME "Indicator"
|
||||
#define EDIT_TEXT_NAME "EditText"
|
||||
#define FAR_AWAY -1000
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
@ -155,6 +158,13 @@ static Widget IndicatorGetTarget (Widget);
|
||||
static int IndicatorGetTargetPosition (Widget);
|
||||
static Boolean IndicatorIsShown (Widget);
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
/* */
|
||||
/* Edit text functions */
|
||||
/* */
|
||||
/*----------------------------------------------------------------------*/
|
||||
static void EditTextCreate (Widget);
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
/* */
|
||||
/* XfeToolBar Resources */
|
||||
@ -622,8 +632,6 @@ Initialize(Widget rw,Widget nw,ArgList args,Cardinal *nargs)
|
||||
tp->indicator = NULL;
|
||||
tp->indicator_target = NULL;
|
||||
|
||||
/* IndicatorCreate(nw); */
|
||||
|
||||
/* Finish of initialization */
|
||||
_XfeManagerChainInitialize(rw,nw,xfeToolBarWidgetClass);
|
||||
}
|
||||
@ -2007,6 +2015,8 @@ IndicatorCreate(Widget w)
|
||||
{
|
||||
XfeToolBarPart * tp = _XfeToolBarPart(w);
|
||||
|
||||
assert( !_XfeIsAlive(tp->indicator ) );
|
||||
|
||||
if (tp->dynamic_indicator)
|
||||
{
|
||||
tp->indicator = XtVaCreateManagedWidget(
|
||||
@ -2149,6 +2159,26 @@ IndicatorGetTargetPosition(Widget w)
|
||||
}
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
/* */
|
||||
/* EditText functions */
|
||||
/* */
|
||||
/*----------------------------------------------------------------------*/
|
||||
static void
|
||||
EditTextCreate(Widget w)
|
||||
{
|
||||
XfeToolBarPart * tp = _XfeToolBarPart(w);
|
||||
|
||||
assert( !_XfeIsAlive(tp->edit_text ) );
|
||||
|
||||
tp->edit_text = XtVaCreateWidget(EDIT_TEXT_NAME,
|
||||
xmTextFieldWidgetClass,
|
||||
w,
|
||||
XmNprivateComponent, True,
|
||||
NULL);
|
||||
}
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
/* */
|
||||
/* XfeToolBar Method invocation functions */
|
||||
@ -2349,9 +2379,149 @@ XfeToolBarGetIndicatorItem(Widget w)
|
||||
/* Make sure the indicator exists */
|
||||
if (!tp->indicator)
|
||||
{
|
||||
IndicatorCreate(w);
|
||||
IndicatorCreate(w);
|
||||
}
|
||||
|
||||
return tp->indicator;
|
||||
}
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
/* */
|
||||
/* XfeToolBar item editting functions */
|
||||
/* */
|
||||
/*----------------------------------------------------------------------*/
|
||||
/* extern */ Widget
|
||||
XfeToolBarGetEditText(Widget w)
|
||||
{
|
||||
XfeToolBarPart * tp = _XfeToolBarPart(w);
|
||||
|
||||
assert( XfeIsToolBar(w) );
|
||||
assert( _XfeIsAlive(w) );
|
||||
|
||||
/* Make sure the edit text exists */
|
||||
if (!tp->edit_text)
|
||||
{
|
||||
EditTextCreate(w);
|
||||
}
|
||||
|
||||
/* Make sure the edit text is realized */
|
||||
if (!_XfeIsRealized(tp->edit_text))
|
||||
{
|
||||
XtRealizeWidget(tp->edit_text);
|
||||
}
|
||||
|
||||
return tp->edit_text;
|
||||
}
|
||||
/*----------------------------------------------------------------------*/
|
||||
/* extern */ void
|
||||
XfeToolBarEditItem(Widget w,
|
||||
Widget item,
|
||||
int label_x,
|
||||
int label_y,
|
||||
int label_width,
|
||||
int label_height)
|
||||
{
|
||||
/* XfeToolBarPart * tp = _XfeToolBarPart(w); */
|
||||
Widget text = NULL;
|
||||
|
||||
assert( XfeIsToolBar(w) );
|
||||
assert( _XfeIsAlive(w) );
|
||||
assert( _XfeIsAlive(item) );
|
||||
assert( _XfeParent(item) == w );
|
||||
|
||||
text = XfeToolBarGetEditText(w);
|
||||
|
||||
if (!_XfeIsAlive(text))
|
||||
{
|
||||
_XfeWarning(w,MESSAGE8);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* Make the text look like the target item */
|
||||
XtVaSetValues(text,
|
||||
XmNbackground, _XfeBackgroundPixel(item),
|
||||
XmNbackgroundPixmap, _XfeBackgroundPixmap(item),
|
||||
XmNforeground, _XfeForeground(item),
|
||||
XmNfontList, XfeFastAccessFontList(item),
|
||||
XmNshadowThickness, 1,
|
||||
XmNborderWidth, 0,
|
||||
XmNeditable, True,
|
||||
XmNcursorPositionVisible, True,
|
||||
XmNmarginWidth, 3,
|
||||
XmNmarginHeight, 1,
|
||||
XmNresizeWidth, False,
|
||||
NULL);
|
||||
|
||||
/* Set the edit text's string */
|
||||
{
|
||||
XmString xmstr = XfeFastAccessLabelString(item);
|
||||
String str = XfeXmStringGetPSZ(xmstr,XmFONTLIST_DEFAULT_TAG);
|
||||
|
||||
if (str)
|
||||
{
|
||||
XmTextFieldSetString(text,str);
|
||||
|
||||
/* Free the psz String */
|
||||
XtFree(str);
|
||||
}
|
||||
}
|
||||
|
||||
/* Place the edit text above the label */
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
int width;
|
||||
int height;
|
||||
Dimension text_margin_width;
|
||||
Dimension text_margin_height;
|
||||
Dimension text_margin_top;
|
||||
Dimension text_margin_bottom;
|
||||
|
||||
XtVaGetValues(text,
|
||||
XmNmarginWidth, &text_margin_width,
|
||||
XmNmarginHeight, &text_margin_height,
|
||||
XmNmarginTop, &text_margin_top,
|
||||
XmNmarginBottom, &text_margin_bottom,
|
||||
NULL);
|
||||
|
||||
x =
|
||||
_XfeX(item) +
|
||||
label_x -
|
||||
text_margin_width -
|
||||
_XfeShadowThickness(text) -
|
||||
_XfeHighlightThickness(text);
|
||||
|
||||
y =
|
||||
_XfeY(item) +
|
||||
label_y -
|
||||
text_margin_top -
|
||||
text_margin_height -
|
||||
_XfeShadowThickness(text) -
|
||||
_XfeHighlightThickness(text);
|
||||
|
||||
width =
|
||||
label_width +
|
||||
2 * text_margin_width +
|
||||
2 * _XfeShadowThickness(text) +
|
||||
2 * _XfeHighlightThickness(text);
|
||||
|
||||
height =
|
||||
label_height +
|
||||
text_margin_bottom + text_margin_top +
|
||||
2 * text_margin_height +
|
||||
2 * _XfeShadowThickness(text) +
|
||||
2 * _XfeHighlightThickness(text);
|
||||
|
||||
_XfeConfigureWidget(text,x,y,width,height);
|
||||
|
||||
XtManageChild(text);
|
||||
|
||||
XRaiseWindow(XtDisplay(item),_XfeWindow(text));
|
||||
|
||||
XmProcessTraversal(text,XmTRAVERSE_CURRENT);
|
||||
}
|
||||
}
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
@ -131,6 +131,23 @@ extern Widget
|
||||
XfeToolBarGetIndicatorItem (Widget w);
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
/* */
|
||||
/* XfeToolBar item editting functions */
|
||||
/* */
|
||||
/*----------------------------------------------------------------------*/
|
||||
extern Widget
|
||||
XfeToolBarGetEditText (Widget w);
|
||||
/*----------------------------------------------------------------------*/
|
||||
extern void
|
||||
XfeToolBarEditItem (Widget w,
|
||||
Widget item,
|
||||
int label_x,
|
||||
int label_y,
|
||||
int label_width,
|
||||
int label_height);
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus /* end C++ */
|
||||
}
|
||||
#endif
|
||||
|
@ -123,6 +123,7 @@ typedef struct _XfeToolBarPart
|
||||
Cardinal num_components; /* Num components */
|
||||
Widget indicator; /* Indicator */
|
||||
Widget indicator_target; /* Indicator target */
|
||||
Widget edit_text; /* Edit text */
|
||||
|
||||
} XfeToolBarPart;
|
||||
|
||||
|
@ -48,7 +48,7 @@ c<Btn1Down>: Focus()\n\
|
||||
/* */
|
||||
/*----------------------------------------------------------------------*/
|
||||
/* extern */ char _XfeLabelDefaultTranslations[] ="\
|
||||
<Btn1Down>: Select()\n\
|
||||
<Btn1Down>: Btn1Down()\n\
|
||||
c<Btn1Down>: Focus()\n\
|
||||
:<Key>osfHelp: Help()\n\
|
||||
<Enter>: Enter()\n\
|
||||
|
Loading…
Reference in New Issue
Block a user